I'm struggling with what seems like should be so simple looking at the codex.

I have a custom post type, let's call it 'portfolio'.

A custom taxonomy for that, let's call it 'clients'.

I can use get_posts() to list all 'portfolio' items but also need the ability to pass in / filter by the 'clients' taxonomy slugs or display all. ("acme,ibm,tbs" - or null/blank)

I've torn apart my sample code so many times that I don't remember anymore what I haven't tried.

Maybe I should instead go with WP_Query()? Sorry for probably such a stupid question, I just can't interpret the example apparently.


Both get_posts() and wp_query() should be able to do this by passing the tax_query array into them.


$query = array(
    'post_type' => 'portfolio',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'tax_query' => array(
            'taxonomy' => 'clients',
            'field' => 'slug',
            'terms' => array( 'acme' )
    'orderby' => 'menu_order',
    'order' => 'ASC'

$posts = get_posts( $query );
  • Ah-ha! I only had one array in the tax_query, not the array of arrays. Thank you so much, my head was about to fall off... – H. Hins Nov 17 '13 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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