Send variables to template

// in archive, taxonomy
<?php $tax = 'news_tax'; ?>
<ul class="uk-margin-medium-bottom uk-margin-medium-top uk-grid-match uk-child-width-1-3@m uk-child-width-1-2@s uk-grid-small" uk-grid="">
  <?php while($i->have_posts()): $i->the_post(); ?>
  <?php if($i->current_post > 0): ?>
  <!-- <loopCardPrimary>-->
  <?php set_query_var('tax', $tax); ?>
  <?php echo get_template_part('partials/loops/card-primary'); ?>
  <!-- </loopCardPrimary>-->
  <?php endif; ?>
  <?php endwhile; wp_reset_postdata(); ?>
</ul>
    
// in loop template
<?php $tax = get_query_var('tax'); ?>

Register custom taxonomy in array

PHP
function add_post_taxonomy() {

  $taxArray = array(
    array(
      "taxName" => 'tax中文名',
      "taxNameEn" =>'taxSlu'
    ),
  );

  foreach ($taxArray as $tax) {
    $labels = array(
      "name" => __( "", "" ),
      "singular_name" => __( $tax['taxName'], "" ),
      "menu_name" => __( $tax['taxName'], "" ),
      "all_items" => __( "所有", "" ),
      "edit_item" => __( "編輯", "" ),
      "view_item" => __( "檢視", "" ),
      "update_item" => __( "更新", "" ),
      "add_new_item" => __( "新增", "" ),
      "new_item_name" => __( "新增", "" ),
      "search_items" => __( "搜尋", "" ),
    );

    $args = array(
      "label" => __( $tax['taxName'], "" ),
      "labels" => $labels,
      "public" => true,
      "hierarchical" => true,
      "label" => $tax['taxName'],
      "show_ui" => true,
      "show_in_menu" => true,
      "show_in_nav_menus" => true,
      "show_admin_column" => true,
      "query_var" => true,
      "rewrite" => array( 'slug' => $tax['taxNameEn'], 'with_front' => true, ),
      "show_admin_column" => true,
      "show_in_rest" => false,
      "rest_base" => $tax['taxNameEn'],
      "show_in_quick_edit" => true,
    );
    register_taxonomy( $tax['taxNameEn'], 'post', $args );
  }
  
}
add_action( 'init', 'add_post_taxonomy' );

Get current term

PHP
global $wp_query;
$term = $wp_query->get_queried_object();

Query the taxonomy terms by ACF field

PHP
<?php 
  $args = array(
    'taxonomy' => 'category',
    'hide_empty' => false
  );
  $cats = get_categories($args);
  $cats_has_feature = array();
  foreach($cats as $cat){
    if (get_field('term_is_feature', 'category_'.$cat->term_id)) {
      $cats_has_feature[] = $cat;	// save the match term in Array
    }
  }

Tags: