Answer the question
In order to leave comments, you need to log in
How to display related posts using the Advanced Custom Fields plugin?
Good afternoon!
There was such a problem.
Using the Toolset plugin, I created 2 sections. This is the program and speakers.
Made the output of the program on the page
<?php
// Заданые переменые
$args = array(
'den_programma' => 'pervyj-den',
'order' => 'ASC'
);
$query = new WP_Query( $args );
?>
<?php if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post(); ?>
<?php }} else {
echo 'Постов не найдено';
} ?>
<?php wp_reset_postdata() ?>
<?php
$posts_field = get_field('field_spikers2');
if( $posts_field ): ?>
<ul>
<?php foreach( $posts_field as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php the_field('your_custom_field',$post); ?>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Answer the question
In order to leave comments, you need to log in
And won't work. Display cycles incorrectly. As I understand it, you have 2 custom entries Programs and Speakers and you want to output data from one to the other, then the technology will be as follows:
1. Make a file to display the Program page, depending on the name of the custom entry, the file should have the same name single-{record slug (programm for example)}.php
2. copy this file to the root of the theme
3. And now, in the file itself, display the necessary Relationships using the regular code from ACF
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question