get a list of posts from Custom Taxonomy

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.

Read More

Can anyone help?

Cheers
John

Related posts

Leave a Reply

1 comment

  1. 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;
    ?>