$terms = get_terms( \'custom_taxonomy\', array(
\'hide_empty\' => false,
));
foreach( $terms as $term ) {
$args = [
\'post_type\' => \'custom_post_type\',
\'post_status\' => \'publish\',
\'tax_query\' => [
[
\'taxonomy\' => \'custom_taxonomy\',
\'field\' => \'id\',
\'terms\' => $term->term_id,
]
]
];
$posts = new WP_Query( $args );
$result[ $term->term_id ] = $posts->posts;
}
因此,您将具有关联数组
$result[TERMID\\u 1]=数组(POST\\u OBJECT\\u OF\\u TERMID\\u 1);
$result[TERMID\\u 2]=数组(POST\\u OBJECT\\u OF\\u TERMID\\u 2);
$result[TERMID\\u 3]=数组(POST\\u OBJECT\\u OF\\u TERMID\\u 3);