WordPress.org

Support

Support » Plugins and Hacks » query posts

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)
  • 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.

    By parameters, I mean you would call query_posts as such:
    query_posts(‘category_name=your_category&showposts=10’);

    Too late. I got it fixed up. Thanks for readiong this far. There is an example of it in action on Codex.

    Ah crap, I remembered seeing it somewhere. For future reference, see here.

    I *really* have to get to work on that query_posts page…

    I still havent quite got the syntax. Does the query go inside the loop. Then the rewind ?

    Use it just before (but not in) the loop it’s to act upon.

    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.

    You shouldn’t need to rewind. The loop counter is reset upon execution so it acts as an implicit rewind.

    Ah cool. But then the loop wont execute.

    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').

    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;

    This looks good. TY.

    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?

    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)
  • The topic ‘query posts’ is closed to new replies.