打印包含分类和Metabox值的术语

时间:2018-12-14 作者:F.A

我创建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; 

1 个回复
最合适的回答,由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 );
希望这会有所帮助

相关推荐

WpQuery中的ORDERBY不区分大小写

我正在尝试按字母顺序对自定义帖子进行排序,我刚刚意识到,大写字母的排序要先于小写字母。有两家餐厅以“Cal”和“CAT”开头,并按字母顺序将“CAT”作为第一个返回。以下是我的$参数:$args = array( \'numberposts\' => -1, \'post_type\' => \'chef\', \'meta_key\' => \'restaurant\', \'orderby\' => \'meta_