0

I have created a Custom Post Type - "magazine_entry" and have registered the taxonomy "division". I have then created several divisions such as, "international", "tokyo", "kansai", etc...

I am trying to display the 3 most recent posts from a single taxonomy of the custom post type.

For example, have

(i will handle the css and html later)

International:
post 1      post 2     post 3    

Tokyo:
post 1      post 2     post 3

etc...

I can get all posts from the custom post type to show up, but I don't know how to get the posts from just one of the taxonomies.

1 Answer 1

1

You should use Taxonomy Parameters available in WP_Query. For example, to get the three recents magazine_entry posts having the international term slug, you can use:

$args = array(
    'post_type' => 'magazine_entry',
    'posts_per_page' => 3
    'tax_query' => array(
        array(
            'taxonomy' => 'division',
            'field' => 'slug',
            'terms' => 'international'
        )
    )
);
$query = new WP_Query( $args );
3
  • Great! Of course it is that simple. I always look for the hard and gritty solutions =/ Now I will start to work on turning the posts per page into Epanel options.
    – user33426
    May 29, 2013 at 7:07
  • In addition, could you tell me where to start in terms of setting a loop that will for example, display the 3 most recent posts from all of the taxonomy categories, automatically, rather than having to set up a new loop each time I make a new category?
    – user33426
    May 29, 2013 at 7:08
  • Get all your terms using get_terms('division').
    – RRikesh
    May 29, 2013 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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