[resolved] List custom post types for the current custom taxonomy (6 posts)

  1. tradiart
    Posted 6 years ago #


    How can I show in a page of a custom post type, a list of the custom post types from the same taxonomy, in case there are several defined?

    For example, in a portfolio, if there are taxonomies "design" and "photography" when I see a project for design, I want to have all design projects listed.

    Seems easy, but I don't know how to do it. Thank you!! :-)

  2. chinmoy29
    Posted 6 years ago #

    Try this

    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    query_posts($query_string . "&cat=".$term->term_taxonomy_id);
  3. tradiart
    Posted 6 years ago #

    Thank you!! :-)

  4. isaachorton
    Posted 5 years ago #

    How do you use this on a sidebar.php?

    I want to do this exact thing, but in my custom sidebar.php Every time I use this code I get unexpected results on the sidebar. Can someone post an actual code example for a sidebar?

  5. Khaled Hakim
    Posted 5 years ago #

    Isaachorton, try coping the same code buy by enclosing it with <?php and ?> tags...

    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    query_posts($query_string . "&cat=".$term->term_taxonomy_id); ?>

    Let me know if that works for you.

  6. jkarlsson
    Posted 5 years ago #

    Nice code!

    How do I get 'term' and term_taxonomy_id?

Topic Closed

This topic has been closed to new replies.

About this Topic