我正在尝试在wordpress上构建一个页面模板,该模板将显示选中自定义字段的列表和类别。
因此,分类法只是默认的woocommerce分类法product_cat
然后,我在product\\u cat分类法中有一个自定义字段,该字段是一个名为collectable
我的设置是主要类别
因此,例如,2个儿童类别具有勾选框collectable
设置为将值1添加到datbase中
所以我正在做一个页面,它将显示所有类别的收藏品选中。
$args = array(
\'post-type\' => \'product\',
\'taxonomy\' => \'product_cat\',
\'hide_empty\' => 0
);
$c = get_categories($args);
$c_keep = array();
foreach($c as $cat){
if (get_field(\'collectable\', \'category_\'.$cat->term_id)) {
$c_keep[] = $cat;
}
}
foreach($c_keep as $cat){
echo $cat->name;
}
但我没有得到任何回报。我甚至把
print_r( $args );
但我仍然得到一个空白(页眉和页脚加载以及查询上方的文本)有人能帮忙吗
******编辑*****
按照建议运行元查询
<?php
$terms = get_terms(
array(
\'taxonomy\' => \'product_cat\',
\'hide_empty\' => false,
\'meta_key\' => \'collectable\',
\'meta_value\' => \'1\',
)
);
$terms = get_terms( $args );
foreach($terms as $cat){ ?>
<?php echo $cat->name; ?> <BR>
<?php
}
print_r( $terms );
?>
这只是买回了所有类别,无论它们是否具有mata\\U值