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 can get a category id or slug for my custom taxonomy just fine, but I then need to be able to get all the posts as an array for that taxonomy entry. My code is as follows:

$args = array(
                'post_type' => 'product',
                'post_status' => 'publish',
                'posts_per_page' => -1
                );
                $the_query = new WP_Query( $args );
                while ( $the_query->have_posts() ) : $the_query->the_post();

endwhile;

When I add 'category_name'=>'my_taxonomy_name' to the args array, it just causes the $the_query to be empty although I know that there is post in there. I have also tried changing it to 'cat'=>22, but this also has the same fault.

Can anyone help?

Cheers John

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Check out the Taxonomy Parameters.

<?php
$args = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_name',
            'field' => 'id',
            'terms' => '22'
        )
    )
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
    //content
endwhile;
?>
share|improve this answer
    
+1 for the tax_query. –  helgatheviking Aug 10 '11 at 4:48
    
Exactly what I was looking for thanks. –  user505988 Jan 3 '12 at 8:59

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.