WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 0 down vote accepted

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'
share|improve this answer
Thanks! Should it be 'cat' => 145? – miles Apr 25 '13 at 20:59
Yes. Corrected it. – s_ha_dum Apr 25 '13 at 21:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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