0

on my "Work" template used for the custom post type with the same name, I have the following code showing a list of titles for every "work". What I want to do is to display just on that list the "Works" that have the same Custom taxonomy than the current one.

<?php $loop = new WP_Query( array( 'post_type' => 'work', 'posts_per_page' => 10, 'orderby' => asc ); while ( $loop->have_posts() ) : $loop->the_post(); ?>

  • Any idea?

    1 Answer 1

    1

    Assuming that you are on a taxonomy or term page then you can simply use:

    //get current term
    $term_slug = get_query_var( 'term' );
    //get current taxonomy
    $taxonomyName = get_query_var( 'taxonomy' );
    $loop = new WP_Query( array(
        'post_type' => 'work', 
        'posts_per_page' => 10, 
        'orderby' => 'ASC',
        $taxonomyName => $term_slug); 
    while ( $loop->have_posts() ) : $loop->the_post(); 
    
    1
    • Thanks for your answer! But couldn't make it work, anyway I will show all projects, not just taxonomy related. Thanks!
      – user7375
      Jul 27, 2011 at 5:45

    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.