我有3个自定义分类法。前两个用于汽车品牌和型号,第三个用于汽车系列。目标是制作一个小部件,根据当前帖子(品牌和型号)列出汽车系列。
function getCarListings() {
global $post;
//$post_id = $post->id;
setup_postdata( $post );
$post_id = get_the_ID();
echo \'<h2>\' . $post_id . \'</h2>\';
$makeArray = get_the_terms($post_id, \'make\'); //make taxonomy for current post
//print_r($makeArray);
$makeTag = $makeArray[0]->name;
//print_r($makeTag );
$modelArray = get_the_terms($post_id, \'model\'); //model taxonomy for current post
$modelTag = $modelArray[0]->name;
//add_image_size( \'realty_widget_size\', 85, 45, false );
$mytaxomomies= array(
// \'relation\' => \'AND\',
array(
\'taxonomy\' => \'make\',
\'terms\' => array( $makeTag ),
\'field\' => \'slug\',
\'operator\'=> \'AND\',
),
array(
\'taxonomy\' => \'model\',
\'terms\' => array( $modelTag ),
\'field\' => \'slug\',
\'operator\'=> \'AND\',
)
);
$args = array(
\'post_type\'=>\'listings\',
\'tax_query\'=> $mytaxomomies,
);
$listings = new WP_Query($args);
$term_array = [];
// $listings->query(\'post_type=listings&posts_per_page=-1\' );
if($listings->found_posts > 0) {
while ($listings->have_posts()) {
$post_get = get_the_ID();
$term_get = get_the_terms($post_get, \'Car_Series\');
$term_array = $term_get;
print_r($term_get);
array_push( $term_array, $term_get);
}
print_r($term_array);
wp_reset_postdata();
}else{
echo \'<p style="padding:25px;">No listing found</p>\';
}
}
顶部获取主页的post id,我可以从中检索汽车品牌和车型。然后,我对这两个分类法进行循环,尝试将第三个分类法术语检索到一个term\\u数组中。但看起来
print_r($term_array)
为空,但
print_r($term_get)
显示我的WP对象。
为什么我不能检索最后一个数组上的术语集合($term_array
)?