Не выводятся значения полей из всех записей - выводится только из первой записи
Есть кастомный тип записей testimonials
add_action('init', 'create_testimonials');
function create_testimonials() {
register_post_type('testimonials',
array(
'labels' => array(
'name' => __('Отзывы'),
),
'capability_type' => 'post',
'taxonomies' => array('category', 'post_tag')
}
Вот вывод
<?
$featured_posts = get_field('testimonials_posts');
if( $featured_posts ):
foreach( $featured_posts as $post ):
setup_postdata($post);
$testimonial_author_prof = get_field('testimonial_author_prof_2');
echo $testimonial_author_prof;
endforeach;
wp_reset_postdata();
endif;
?>
Но
echo $testimonial_author_prof;
Выводит только значение из первого поста. Как вывести значения всех постов?
Ответы (1 шт):
Автор решения: Valerii Vasiliev
→ Ссылка
Вывод сделан неправильно. Сделайте через WP_Query
<?php
$args = [
'post_type' = > 'testimonials',
'post_status' => 'publish',
'post_per_page' => -1,
'orderby' => 'date',
'order' => 'desc'
];
$the_query = new \WP_Query($args);
if ($the_query->have_posts()) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$testimonial_author_prof = get_field('testimonial_author_prof_2', $the_query->post->ID);
echo $testimonial_author_prof;
endwhile;
endif;
wp_reset_query();
?>