Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

    share|improve this question

    1 Answer 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(); 
    
    share|improve this answer
        
    Thanks for your answer! But couldn't make it work, anyway I will show all projects, not just taxonomy related. Thanks! –  user7375 Jul 27 '11 at 5:45

    Your Answer

     
    discard

    By posting your answer, you agree to the privacy policy and terms of service.

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