Want to get posts by tag in WordPress? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$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 '<li>'; the_title(); echo '</li>'; endwhile; endif; $wp_query = null; $wp_query = $original_query; wp_reset_postdata(); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.