具有:
Named
A - Custom Post Type ====> services_cpt
B - Custom Taxanomy ====> service_tax
C - Custom Tax Term ====> personal
我无法列出(筛选)所有分类在下的帖子(services\\u cpt Custom Post Type)
personal
学期
<?php
$custom_terms = get_terms(\'service_tax\');
foreach($custom_terms as $custom_term) {
$args = array(\'post_type\' => \'services_cpt\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'service_tax\',
\'field\' => \'slug\',
\'terms\' => \'personal\'
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo \'<div class="col-md-4">\';
echo \'<a class="item-box" href="\'.get_permalink().\'">\'.get_the_title().\'</a>\';
echo \'</div>\';
while($loop->have_posts()) : $loop->the_post();
endwhile;
}
}
?>
你能看看这个,告诉我我做错了什么吗?
SO网友:attoma
Check this code:
<?php
$custom_terms = wp_get_post_terms($post->ID, \'service_tax\');
$count = count($custom_terms);
if ( $count > 0 ) {
foreach($custom_terms as $custom_term) {
$args = array(\'post_type\' => \'services_cpt\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'service_tax\',
\'field\' => \'slug\',
\'terms\' => $custom_term
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo \'<div class="col-md-4">\';
echo \'<a class="item-box" href="\'.get_permalink().\'">\'.get_the_title().\'</a>\';
echo \'</div>\';
while($loop->have_posts()) : $loop->the_post();
endwhile;
}
}
}
?>