Support » Fixing WordPress » Trouble adding posts_per_page limit to a query

  • I can’t get the posts_per_page to blend into this query… can’t find any writing on this script which is just using “query” instead of “query_posts”, so confused, please help!

    $tempWPQuery = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    // Issue a query that returns 4 posts in a particular category
    while ($wp_query->have_posts()):
    //display stuff instructions..
Viewing 2 replies - 1 through 2 (of 2 total)
  • To add additional parameters to the query, simply separate them by the & symbol. For example:


    The above example limits the query to return only 5 results. As is, this will only display 5 posts on the first page. If you want additional pages to work, you need to pass a long the paged paramter which essentially says which page to display posts from:

    $paged = ( $wp_query->get('paged') ) ? $wp_query->get('paged') : 1;
    $wp_query->query('category_name=featured-item&posts_per_page=5&paged=' . $paged);

    ohhhh thank you so much Jacob, I had almost tried that, mine had two sets of single-quotes separated by a comma and it wasn’t working that way.

    i hate to be a given-an-inch-takin-a-mile guy but any chance this other puzzle of mine makes sense to you?

    thanks either way!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trouble adding posts_per_page limit to a query’ is closed to new replies.