也许你可以试试这个:
<?php
$post_type = \'your_current_post_type_name\';
$tax = \'your_taxonomy_name\';
$tax_terms = get_terms($tax);
if ($tax_terms) {
foreach ($tax_terms as $tax_term) {
$args=array(
\'post_type\' => $post_type, // Here you will tell Wordpress only query on this post type
"$tax" => $tax_term->slug,
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'caller_get_posts\'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
...
<?php
endwhile;
}
wp_reset_query();
}
}
?>
使用
var_dump($tax_term)
您可以准确地验证可用的属性(名称、slug、ID、count等)-如果一切都按预期运行,那么所有这些属性都应该可用:
stdClass Object
(
[term_id] =>
[name] =>
[slug] =>
[term_group] =>
[term_order] =>
[term_taxonomy_id] =>
[taxonomy] =>
[description] =>
[parent] =>
[count] =>
[object_id] =>
)