Title: query_posts by tag and showposts
Last modified: August 20, 2016

---

# query_posts by tag and showposts

 *  [evaneckard](https://wordpress.org/support/users/evaneckard/)
 * (@evaneckard)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-by-tag-and-showposts/)
 * I can’t seem to get this to work (even though it seems like it should from the
   codex).
 *     ```
       <?php if (have_posts()) : ?>
       <?php query_posts("showposts=4&tag=featured"); ?>
       <?php while (have_posts()) : the_post();?>
       ```
   
 * Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-by-tag-and-showposts/#post-2206213)
 * what is it doing or not doing?
 * is there more code to it?
 * you could paste the whole code of the template (or whatever you are working on)
   into a [http://pastebin.com/](http://pastebin.com/) and post the link to it here.
 *  Thread Starter [evaneckard](https://wordpress.org/support/users/evaneckard/)
 * (@evaneckard)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-by-tag-and-showposts/#post-2206215)
 * I was simply trying to open the loop showing only 4 posts tagged with “featured”
 * If I use just showposts=4, the loops shows the most current 4 posts. If I use
   just the tag, nothing shows even though I have posts tagged as such.
 * Looking at the codex, it seems it should work.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-by-tag-and-showposts/#post-2206216)
 *     ```
       <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       query_posts('posts_per_page=4&tag=featured&paged=. $paged); ?>
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-by-tag-and-showposts/#post-2206217)
 * you could try a variation:
 *     ```
       <?php $args = array(
       'posts_per_page' => 4,
       'tag_slug__in' => array('featured')
       );
       query_posts( $args ); ?>
       <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post();?>
       ```
   
 * [http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters)
 * or check the spelling; or try and use the tag ID …

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘query_posts by tag and showposts’ is closed to new replies.

## Tags

 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [tag](https://wordpress.org/support/topic-tag/tag/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/query_posts-by-tag-and-showposts/#post-2206217)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
