Shing
@Shing

Как вывести одному посту несколько значений таксономии (ACF)?

У постов есть таксономия.
У одного поста может быть несколько выбранных таксономий одного типа.
Сейчас выводится только одна таксономия, остальные выбранные игнорируются.
Как вывести несколько таксономий одного типа?

Сейчас вот так:
<?php
global $post;
// load all 'category' terms for the post
$terms = get_the_terms($post->ID, 'pro');
// we will use the first term to load ACF data from
if( !empty($terms) )
{ $term = array_pop($terms);
$term_link = get_term_link( $term );
$custom_field = get_field('picon', $term ); ?>
<a href="<?php echo $term_link ?>"><img style="float: left; padding-right: 15px;" src="<?php echo $custom_field; ?>" class="img-circle img-responsive align-center prep" /> 
</a><h3><?php echo $term->name; ?></h3>
<?php the_field('pnum', $term); ?>
<?php // do something with $custom_field
} ?>
  • Вопрос задан
  • 240 просмотров
Решения вопроса 1
deniscopro
@deniscopro Куратор тега WordPress
WordPress-разработчик, denisco.pro
Видимо, как-то так:
<?php
global $post;
// load all 'category' terms for the post
$terms = get_the_terms($post->ID, 'pro');
// we will use the first term to load ACF data from
if( !empty($terms) )
{ 
foreach($terms as $term) {
$term_link = get_term_link( $term );
$custom_field = get_field('picon', $term ); ?>
<a href="<?php echo $term_link ?>"><img style="float: left; padding-right: 15px;" src="<?php echo $custom_field; ?>" class="img-circle img-responsive align-center prep" /> 
</a><h3><?php echo $term->name; ?></h3>
<?php the_field('pnum', $term); ?>
<?php // do something with $custom_field
}
} ?>
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
ddv88
@ddv88
Binance Futures
Шта? global в 2k17?
Worpress, что ты делаешь ахаха прекрати.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы