WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 0 down vote accepted

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 );
share|improve this answer
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 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.