E
E
Eugene Zhadko2021-07-31 17:53:30
Taxonomy
Eugene Zhadko, 2021-07-31 17:53:30

How to display ACF taxonomy field in WordPress archived posts?

There is a custom post type: Store
There is a custom taxonomy: Metro
There is an additional field for the Metro taxonomy , created through the ACF plugin: Metro Branch

When displaying records on the archive page, it is not possible to display the " Metro Branch " field .

$args = array(
  'post_type' => 'magaziny',
);
$products = new WP_Query( $args );
if( $products->have_posts() ) {
  while( $products->have_posts() ) {
    $products->the_post();

<div id="post-<?php the_ID(); ?>">
  <div class="item">
    <div class="item-info">
      <div class="item-location">
        <div class="flex">
          <div class="flex item-metro">
            <div class="item-location-pointer" style="background: #B6127D;"></div>
            <span>
              <?php
                $metros = get_the_terms( get_the_ID(), 'metro' );
                // так как функция вернула массив, то логично будет прокрутить его через foreach()
                foreach( $metros as $metro ){
                  echo $metro->name;

                }
              ?>
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yarovikov, 2021-07-31
@Jeka778

Inside a loop?

$t = $metro->taxonomy. '_' . $metro->term_id;
$vetka = get_field('vetka', $t);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question