this has taken up most of my afternoon, but i just cannot get it to work properly.

The issue is when i try to add a catergory argument to my custom loop, whether it is an include or exclude. When i add the argument it simply breaks the loop, i will have a working loop displaying fine, then i add a catergory arg, save, and f5 and voila i have a loop that doesnt display anything.

I have used both query_posts and WP_Query and am still having the issue, and it's not a simple case of me providing an invalid cat id number.

Hopefully somebody can point out where i went wrong.

Below is my loop, if you need the entire template page let me know.


$tshirt_query = new WP_Query ('post_type=tshirt&posts_per_page=30');
while($tshirt_query->have_posts()) : $tshirt_query->the_post(); ?>

<div class="tbox">
    <a href="<?php the_permalink() ?>" alt="<?php the_title(); ?>"><?php   the_post_thumbnail( array(234,234,true) ); ?></a>

    <div class="tcaption">
        $thetitle = $post->post_title; 
        $getlength = strlen($thetitle);
        $thelength = 23;
        echo substr($thetitle, 0, $thelength);
        if ($getlength > $thelength) echo "...";

Just as additional info - I am using a custom post type (tshirt) and all off my custom posts are tagged in each of my four custom taxonomies (vendor, size, genre, color). So essentialy every post will have atleast one tag from each of the taxonomies.

I hope someone can help, and in the mean time a big thanks!


  • Can you post the query you've tried that blanks the loop? Nov 8, 2011 at 19:22
  • here you go kevin - ('cat=55&post_type=tshirt&posts_per_page=30') i have tried placing that cat= in different positions and even on its own, without other args.
    – user10106
    Nov 8, 2011 at 19:25
  • Are you trying to get the category or the custom taxonomy of this post type? Just curious because your original question referenced taxonomies named vendor, size, genre, color. Nov 8, 2011 at 19:33
  • no, i just added the info as suppemental, didnt know if it would be needed. Basically i want a catergory of the post type to display regardless of its taxonomy. so cat=55 is the color black, i would like all posts that have the catergory black to display.
    – user10106
    Nov 8, 2011 at 19:39

1 Answer 1


First thing is that your query syntax is correct so the problem is either that there are no tshirt posts under the category term id your querying for or the post type was not registered properly to use categories: 'taxonomies' => array( 'category' )

You can test for this by adding a var_dump() to your loop that works without adding the cat.

while($tshirt_query->have_posts()) : $tshirt_query->the_post();

$categories = get_the_category();
    foreach ( $categories as $category ) {

var_dump( $category );

This will give you an array of each category associated with the post to determine where the problem lies.

Example $category dump from a custom post type in the world category with an id of 4:

  public 'term_id' => &string '4' (length=1)
  public 'name' => &string 'World' (length=5)
  public 'slug' => &string 'world' (length=5)
  public 'term_group' => string '0' (length=1)
  public 'term_order' => string '1' (length=1)
  public 'term_taxonomy_id' => string '4' (length=1)
  public 'taxonomy' => string 'category' (length=8)
  public 'description' => &string '' (length=0)
  public 'parent' => &string '0' (length=1)
  public 'count' => &string '3' (length=1)
  public 'object_id' => string '86' (length=2)
  public 'cat_ID' => &string '4' (length=1)
  public 'category_count' => &string '3' (length=1)
  public 'category_description' => &string '' (length=0)
  public 'cat_name' => &string 'World' (length=5)
  public 'category_nicename' => &string 'world' (length=5)
  public 'category_parent' => &string '0' (length=1)
  • Cheers Chris for your very indepth answer. However i managed to fix the problem last night. First thing is that there is tshirts under all of the catergories i was trying. The issue was just "cat=55" was not pulling anything. I fixed the problem with "taxonomy_name=$category_slug". I am not sure why this works and the simple "cat=" does not. Any ideas why? @Chris_O
    – user10106
    Nov 9, 2011 at 7:53
  • Not sure why it won't work using the id. Have you tried putting the $args instead of the query string method?
    – Chris_O
    Nov 9, 2011 at 18:26

Your Answer

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