i have one custom post type 'game' and one custom taxonomy 'console', which is shared by 'game' and 'post'. Now I created a new PHP 'taxonomy-console' and I want to separately display posts from 'post' on the left and posts from 'game' on the right.

the code I am using is:

    <?php  $slug = $term->slug; 
           $query = new WP_Query(array( 'post_type' => 'post', 'order'=>'DESC', 'tax_query' => array( array( 'taxonomy' => 'console', 'field'    => 'slug', 'terms'    => $slug, ), ), ) );
                if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
                    /* bla bla bla */
    <?php endwhile; endif; ?>

But neither this nor 'post_type' => 'game' are displaying anything.

The thing is, I am using the same exact code on another taxonomy page, the only difference is that it is registered with only one post_type and doesn't share two post types.

  • your array is missing a comma before tax_query, do you have debugging enabled?
    – Milo
    May 23, 2016 at 20:01
  • sorry, just made the mistake while writing the code here. that doesn't seem to be the problem
    – lamedoo
    May 23, 2016 at 20:34
  • where do you set $term? have you verified that contains what you expect? you can var_dump($query) and see how the query vars are being set and the SQL being sent to the DB.
    – Milo
    May 23, 2016 at 21:32
  • isn't $term already predefined in taxonomy php?
    – lamedoo
    May 24, 2016 at 10:10
  • the thing is, if I put the slug of one specific term in the 'terms', then it displays the posts, but I want it to retrieve the slugs automatically for each term
    – lamedoo
    May 24, 2016 at 10:26

1 Answer 1


I can't comment so I have to provide an answer which I don't have a full answer. If I were you I would print_r($slug) and see what it gives you. The $slug variable is most likely not in a format that 'terms' can accept.

  • Ok so i tried that and it displayed nothing, so i used @Milo's get_queried_object_id and then it displayed the ID, so thanks to both of you so much !!!
    – lamedoo
    May 27, 2016 at 11:09

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.