获取具有 ACF 真布尔值的自定义分类术语

Get custom taxonomy terms with a true boolean value of ACF

我有一个名为 frontpage 的高级自定义字段。是true/false类型。

我正在尝试恢复所有标记为 true 的条款。我试过这个:

$args = array(
      'hide_empty' => 0,
      'key' => 'frontpage',
      'compare' => '==',
      'value' => '1'
);

$terms = get_terms( 'people', $args );

if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
    foreach ( $terms as $term ) {
        echo $term->name;
    }
}

但这returns所有条款,不管真假。

我怎样才能得到正确标记的条款?谢谢!

编辑: ACF 文档说如何恢复 post,而不是如何恢复条款: https://www.advancedcustomfields.com/resources/true-false/

EDIT2:返回的对象不包含自定义字段,仅包含标准元数据:

Array ( 
[0] => WP_Term Object ( 
  [term_id] => 2 
  [name] => Cristina Aiken Soux 
  [slug] => cristina-aiken-soux 
  [term_group] => 0 
  [term_taxonomy_id] => 2 
  [taxonomy] => personas 
  [description] => Cras in elementum enim, vitae volutpat sapien. Duis at sem in quam ultrices hendrerit. Class aptent taciti sociosqu ad litora torquent. 
  [parent] => 0 
  [count] => 1 
  [filter] => raw )
)

那么,第一个问题是,如何恢复每个词条的元字段?

我会尝试此查询来检索某个 $term 的帖子,该帖子针对给定的 $taxonomy 将 $acf_field_name 设置为 true:

 $args = array(
   'hide_empty' => 0,
     'meta_query' => array(
         array(
            'key' => $acf_field_name,
            'compare' => '==',
            'value' => '1'
         )
     ),
     'tax_query' => array(
          array(
             'taxonomy' => $taxonomy,
             'field' => 'slug',
             'terms' => $taxonomy_terms,
          ),
     )
 );
 $query = get_posts( $args );

最后,我使用了另一种方法:获取所有术语,并在循环中仅输出自定义字段中标记的术语。

$args = array(
        'hide_empty' => 0
  );

  $terms = get_terms( $taxonomy, $args );
  if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
      foreach ( $terms as $term ) {
        $custom_field = get_field('custom_field', $term);
        if( $custom_field == '1' ):
            echo $term->name;
        php endif; ?>