Wordpress: trying to get posts by tag

前端 未结 3 1211
忘了有多久
忘了有多久 2020-12-10 02:42

I\'ve written some code which automatically creates some posts and adds a tag to them. I can see the tags in the \'All posts\' admin panel and I can click on the posts \'Ta

3条回答
  •  渐次进展
    2020-12-10 03:19

    Try this

    $original_query = $wp_query;
    $wp_query = null;
    $args=array('posts_per_page'=>5, 'tag' => $brand_name);
    $wp_query = new WP_Query( $args );
    if ( have_posts() ) :
        while (have_posts()) : the_post();
            echo '
  • '; the_title(); echo '
  • '; endwhile; endif; $wp_query = null; $wp_query = $original_query; wp_reset_postdata();

提交回复
热议问题