How to get the posts of a custom taxonomy term

This question has different answers in this specific WordPress question, they may be of help:

Display all posts in a custom post type, grouped by a custom taxonomy

Personally I used this method that worked for me just fine:

$terms = get_terms('tax_name');
$posts = array();
foreach ( $terms as $term ) {
    $posts[$term->name] = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'post_type', 'tax_name' => $term->name ));
}

Editing it to your scenario this should work:

$terms = get_terms('producer');
$posts = array();
foreach ( $terms as $term ) {
    $posts[$term->name] = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'movie', 'tax_name' => $term->name ));
}

Now you can get your posts:

print_r($posts["WarnerBros"]);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)