Title: query posts
Last modified: August 18, 2016

---

# query posts

 *  [Root](https://wordpress.org/support/users/root/)
 * (@root)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/)
 * Does anyone happen to know where an expo on query_posts is to be found please.
   On Codex it is descibed as coming shortly. (1.5).

Viewing 15 replies - 1 through 15 (of 36 total)

1 [2](https://wordpress.org/support/topic/query-posts/page/2/?output_format=md) 
[3](https://wordpress.org/support/topic/query-posts/page/3/?output_format=md) [→](https://wordpress.org/support/topic/query-posts/page/2/?output_format=md)

 *  [ifelse](https://wordpress.org/support/users/ifelse/)
 * (@ifelse)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178328)
 * query_posts allows you to reuse the $wp_query object. By passing in parameters
   to query_posts, that query will be performed.
 * This will reset the loop counter and rebuild the collection of posts allowing
   you to go back through the_loop again.
 *  [ifelse](https://wordpress.org/support/users/ifelse/)
 * (@ifelse)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178330)
 * By parameters, I mean you would call query_posts as such:
    query_posts(‘category_name
   =your_category&showposts=10’);
 *  Thread Starter [Root](https://wordpress.org/support/users/root/)
 * (@root)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178331)
 * Too late. I got it fixed up. Thanks for readiong this far. There is an example
   of it in action on Codex.
 *  [ifelse](https://wordpress.org/support/users/ifelse/)
 * (@ifelse)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178332)
 * Ah crap, I remembered seeing it somewhere. For future reference, [see here](http://codex.wordpress.org/The_Loop#Advanced_Use).
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178335)
 * I *really* have to get to work on that query_posts page…
 *  Thread Starter [Root](https://wordpress.org/support/users/root/)
 * (@root)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178344)
 * I still havent quite got the syntax. Does the query go inside the loop. Then 
   the rewind ?
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178348)
 * Use it just before (but not in) the loop it’s to act upon.
 *  Thread Starter [Root](https://wordpress.org/support/users/root/)
 * (@root)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178352)
 * Then rewind? I ask because it isnt running smoothly. I have tried most combos.
   
   Or is the rewind built into the query as it seems ? In the Codex example the 
   query sits first but then the loop only executes the query.
 *  [ifelse](https://wordpress.org/support/users/ifelse/)
 * (@ifelse)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178358)
 * You shouldn’t need to rewind. The loop counter is reset upon execution so it 
   acts as an implicit rewind.
 *  Thread Starter [Root](https://wordpress.org/support/users/root/)
 * (@root)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178359)
 * Ah cool. But then the loop wont execute.
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178360)
 * rewind is somewhat unrelated to query_posts. Depending on what you’re trying 
   to do, an option may be to reinitialize the default loop through `query_posts('
   showposts')`.
 *  [ifelse](https://wordpress.org/support/users/ifelse/)
 * (@ifelse)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178361)
 * Here’s roughly what you would be doing:
    `if (have_posts()) : while (have_posts()):
   the_post(); the_title(); endwhile;  //now run a new query query_posts('category_name
   =site&showposts=10'); //as $wp_query is reinitialise, let's run the_loop while(
   have_posts()) : the_post(); the_title(); endwhile; endif;
 *  Thread Starter [Root](https://wordpress.org/support/users/root/)
 * (@root)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178365)
 * This looks good. TY.
 *  [lawtai](https://wordpress.org/support/users/lawtai/)
 * (@lawtai)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178385)
 * The thing with the query post is that it bypasses any password protection if 
   you’re using PW’s. Know of a way to still include the PW protection?
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/query-posts/#post-178425)
 * lawtai: Try reusing the code for that from `the_content()` and perform an if/
   else just after the start of your custom loop:
 * `<?php if(!empty($post->post_password)) :
    if(stripslashes($_COOKIE['wp-postpass_'.
   COOKIEHASH]) != $post->post_password) { // and it doesn't match the cookie $output
   = get_the_password_form(); echo $output; } else : ?>
 * ~drop your regular loop stuff here ~
 * `<? endif; ?>`
 * Don’t know if it’ll work, but worth a shot.

Viewing 15 replies - 1 through 15 (of 36 total)

1 [2](https://wordpress.org/support/topic/query-posts/page/2/?output_format=md) 
[3](https://wordpress.org/support/topic/query-posts/page/3/?output_format=md) [→](https://wordpress.org/support/topic/query-posts/page/2/?output_format=md)

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

## Tags

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

 * 36 replies
 * 8 participants
 * Last reply from: [davidchait](https://wordpress.org/support/users/davidchait/)
 * Last activity: [21 years, 1 month ago](https://wordpress.org/support/topic/query-posts/page/3/#post-179034)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
