I originally had this query on a posts category page:

        <?php $page_query = new WP_Query('post_type=post&cat=145'); ?>

Which worked, but it only displayed the first 4 posts. So I wanted to display all the posts from the category, as well as change the posts per page limit, as well as set the orderby for good measure. However, this query returns EVERY post on my site, regardless of category:

        <?php $page_query = new WP_Query('post_type=post&cat=145'. '&posts_per_page=-1&cat' . '&orderby=date&order=asc'); ?>

Seems like it should work in theory. Any ideas what I'm doing wrong?

1 Answer 1


You are passing the cat parameter twice-- the second time is empty.

$page_query = new WP_Query(
    '&posts_per_page=-1&cat' . // <-- here

Maybe it is just me, but I find those query-string-like parameters hard to read and hard to keep straight. I'd advise you to create a proper array.

$page_query = new WP_Query(
    array (
        'post_type' => 'post',
        'cat' => 145, 
        'posts_per_page' => -1,
        'orderby' => 'date',
        'order' => 'asc'
  • 1
    Thanks! Should it be 'cat' => 145?
    – Ten Sleep
    Commented Apr 25, 2013 at 20:59
  • Yes. Corrected it.
    – s_ha_dum
    Commented Apr 25, 2013 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.