Title: Help with query posts
Last modified: August 19, 2016

---

# Help with query posts

 *  Resolved [a-kyle](https://wordpress.org/support/users/a-kyle/)
 * (@a-kyle)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/help-with-query-posts/)
 * SO I have this piece of code that should display the posts of the selected categories
   by their ID. this piece of code is in both the footer and the drop down menu.
 * on my home page (a static page) it displays ONE post that when clicked on goes
   no where, and the same goes for the drop down.
 * on the blog page it displays up to 10 or more posts when it should only display
   5.
 * can some one tell me what’s wrong with this code?
 *     ```
       <h4><?php _e('Recent Posts'); ?></h4>
       			<?php query_posts('showposts=5','cat=3,4,9,13,5,6,15,7');
       			wp_reset_query();?>
   
       			<?php while (have_posts()) : the_post(); ?>
       				<li><em>(<?php the_time('M d') ?>)</em><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> </li>
       			<?php endwhile;?>
       ```
   

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/help-with-query-posts/#post-1541775)
 * `<?php query_posts('showposts=5','cat=3,4,9,13,5,6,15,7');`
    Incorrect format.
   Try: `<?php query_posts('posts_per_page=5&cat=3,4,9,13,5,6,15,7');`
 * `wp_reset_query();`
    Should be **after** the Loop – not before it. You’re destroying
   the custom query that you just created.
 * I’d suggest reviewing some of the examples on [http://codex.wordpress.org/Function_Reference/query_posts#Category_Parameters](http://codex.wordpress.org/Function_Reference/query_posts#Category_Parameters)
 *  Thread Starter [a-kyle](https://wordpress.org/support/users/a-kyle/)
 * (@a-kyle)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/help-with-query-posts/#post-1541787)
 * Thanks for the help but that did nothing for me. For example on the local host
   I have blog posts (test posts) going back as far as the 22nd of may. (fixed a
   date error)
 * on the main site, the actual site, their is no post going back that far and yet
   I am getting a test post to show up called Adam. this data base and word press
   installation isn’t even 2 weeks old.
 * 0o
 * I am assuming the code should look like:
 *     ```
       <h4><?php _e('Recent Posts'); ?></h4>
   
       			<?php while (have_posts()) : the_post(); ?>
       				<li><em>(<?php the_time('M d') ?>)</em><a href="<?php the_permalink() ?>">				<?php the_title(); ?></a> </li>
       			<?php endwhile;?>
   
       		<?php query_posts('posts_per_page=5&cat=3,4,9,13,5,6,15,7');
       			wp_reset_query();?>
       ```
   
 *  Anonymous User
 * (@anonymized-3085)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/help-with-query-posts/#post-1541792)
 * try:
 *     ```
       <h4><?php _e('Recent Posts'); ?></h4>
               <?php query_posts('posts_per_page=5&cat=3,4,9,13,5,6,15,7'); ?>
       	<?php while (have_posts()) : the_post(); ?>
       	   <li><em>(<?php the_time('M d') ?>)</em><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> </li>
       	<?php endwhile;?>
               <?php wp_reset_query();?>
       ```
   
 *  Thread Starter [a-kyle](https://wordpress.org/support/users/a-kyle/)
 * (@a-kyle)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/help-with-query-posts/#post-1541811)
 * Ya I figured that out last minute. LOL Thanks guys

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

The topic ‘Help with query posts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [a-kyle](https://wordpress.org/support/users/a-kyle/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/help-with-query-posts/#post-1541811)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
