Not sure what's going on - here's a look at my code:

$args = array(
    'orderby' => 'title',
    'show_posts' => '-1', 
    'posts_per_page' => '-1', 
    'cat' => $goalsCat->cat_ID,
    'post_type' => 'Goals',
    'author' => $current_user_id,
    'post_status' => 'publish',

$wp_query_assigned = new WP_Query($args); 

if ( $wp_query_assigned->have_posts() ) : 

    while ($wp_query_assigned->have_posts()) : $wp_query_assigned->the_post();
        $title = get_the_title();
        echo '<p>'.$title.'</p>';
else : 

    echo '<p>You have no set Goals';


If I remove the category param from the $args array, it returns all the posts in the category, so I know that this part is working correctly. But when I add the category, it returns nothing. I am able to confirm that there are posts in each category and that all the ID's are correct.

Any thoughts?

  • So, the problem is orderby as the title suggests or with the category param? Can you show us what is $goalsCat object or at least the value of $goalsCat->cat_ID? Also, you have a typo in your code: orderly should be orderby.
    – cybmeta
    Jan 20 '15 at 17:11
  • Sorry, yes, I fixed the typo on 'orderby'. $goalsCat->cat_ID returns the id of the category. Jan 20 '15 at 18:42

You have a couple of issues here looking at your code and tags used to tag your question

  • show_posts is wrong. It is depreciated in favor of posts_per_page. Also, it should be showposts.

  • You cannot use showposts and posts_per_page together. You should only use posts_per_page

  • Don't use camelcase in you custom post type names, they are really problematic when it comes to templates. Only use underscores and lowercase letters. The same goes for custom taxonomies

  • I do believe you are using a custom taxonomy and not build-in categories, which is the number one suspect failing your code. The category parameters does not work with custom taxonomies, you should use a tax_query. But first, read this post to learn what a category is and what a term and taxonomy is

  • Awesome - it's been a bit since I've been in WP dev mode. Totally forgot about the tax_query stuff and the differences in WP between all the different cats and taxonomies. Thanks for your help! Jan 20 '15 at 22:34
  • My pleasure, glad it helped. Enjoy :-) Jan 21 '15 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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