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.

I am trying to listing posts from a single category of my custom taxonomy.

I have created a custom post type called "news" and a custom taxonomy called "instituteName".

I then created a number of categories using the "instituteName" taxonomy.

I would now like to display the posts from only a single category. e.g. i have created a category "businessSchool" underneath "instituteName" taxonomy. Now I want to display the four latest post the "businessSchool" category only.

screenshot

Any help would be greatly appreciated!

share|improve this question

2 Answers 2

You can do it using custom WP_Query:

$my_query = new WP_Query( array(
    'post_type'=>'news',
    'posts_per_page'=>4,
    'tax_query'=>array(
        array(
            'taxonomy'=>'instituteName',
            'field'=>'slug',
            'terms'=>'businessschool'  // change to real slug
        )
     )
) );

while ( $my_query->have_posts ) {
    $my_query->the_post();
    // display post
}

PS. This link would be helpful, I guess: http://codex.wordpress.org/Class_Reference/WP_Query

share|improve this answer
    
Thanks for the help, But its not working...:( I have tried "<?php query_posts( array('post_type' => 'news', 'taxonomy'=>'InstituteName', 'category_name' => 'businessSchool', 'showposts' => 4 ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>"... –  Gaurav Jul 10 '13 at 11:16
    
But not working, If i don't add category name, then its working but display all the post underneath "InstituteName" taxonomy. –  Gaurav Jul 10 '13 at 11:17
    
You shouldn't use 'category_name' - your custom taxonomy IS NOT category. Take a look at my code - it uses tax_query and you should use it... The only thing you have to look out is replacing businessschool with correct term slug. –  Krzysiek Dróżdż Jul 10 '13 at 11:46
    
Thanks, Tried the same code, but not working, Even not displaying single post..:( –  Gaurav Jul 10 '13 at 11:55
    
Are you sure that you modify it correctly? –  Krzysiek Dróżdż Jul 10 '13 at 12:41

@Krzysiek answer above didn't work because have_posts is a method not a property. It should be have_posts() not have_posts. Here's the corrected code:

$my_query = new WP_Query( array(
    'post_type'=>'news',
    'posts_per_page'=>4,
    'tax_query'=>array(
        array(
            'taxonomy'=>'instituteName',
            'field'=>'slug',
            'terms'=>'businessschool'  // change to real slug
        )
     )
) );

while ( $my_query->have_posts() ) {
    $my_query->the_post();
    // display post
}
share|improve this answer

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.