我创建metaboxserial_language
将ACP插件插入自定义分类法名称为serial
.
我只想获取术语,其中自定义字段值为english, arabic
.
如何仅获取具有自定义字段值的术语english or arabic
?
$wcatTerms = array(
\'get_terms\' => \'serial\',
\'hide_empty\' => 0,
\'parent\' =>0,
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'get_terms\' => \'serial\',
\'field\' => \'serial_language\',
\'value\' => array( \'english\', \'arabic\' ),
)
));
foreach($wcatTerms as $wcatTerm) :
echo \'<a href="\' .get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ). \'">\' .$wcatTerm->name. \'</a>\';
endforeach;
最合适的回答,由SO网友:Tejas Gajjar 整理而成
尝试以下操作:
$args = array(
\'hide_empty\' => false,
\'relation\' => \'OR\',
array(
\'key\' => \'serial_language\',
\'value\' =>\'english\',
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'serial_language\',
\'value\' =>\'arabic\',
\'compare\' => \'LIKE\'
),
\'taxonomy\' => \'serial\',
);
$terms = get_terms( $args );
希望这会有所帮助