V
V
VitStar2016-06-15 10:38:03
Taxonomy
VitStar, 2016-06-15 10:38:03

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() ?>

Inside this loop, I need to output the speakers. (Speakers added separately). Thought to do it with Advanced Custom Fields plugin and Relationship fields. but that's the problem is not displayed.
I derive a standard function from the documentation
<?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; ?>

Does not work. Maybe someone did something similar.
Thanks in advance!!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Abramovich, 2016-06-15
@artikus

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 question

Ask a Question

731 491 924 answers to any question