1

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

1 Answer 1

4

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;
?>
0

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.