Aleš Sýkora wrote

ACF Repeater Post Object in oxygen code block

2. 10. 2020 in ,

You are using gutenberg and ACF and toolset and need to add related posts in slider, which you choose at the post you are editing? Also you need to put them in the content, exactly where you want?

  1. Create ACF repeater with Post Object field inside
  2. Create Oxygen Block for Gutenberg
  3. Add code block and Flickity
  4. Edit your post and add the Oxygen Block slider.

Code example:

<div class="rep-carousel">
  <?php global $post; ?>
  <?php if (have_rows('vyber_clanku')) : //vyber_clanku is ACF repeater field slug 
  ?>
    <?php while (have_rows('vyber_clanku')) :  the_row(); ?>
      <?php $post_object = get_sub_field('clanek'); //clanek is post object field slug 
      ?>
      <?php if ($post_object) : ?>
        <?php // override $post
        $post = $post_object;
        setup_postdata($post);
        ?>
        <div class="rep-carousell-cell">
          <div class="slider-image"><?php the_post_thumbnail('full'); ?></div>
          <div class="p-1em">
            <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
          </div>
        </div>
        <?php wp_reset_query(); // IMPORTANT - reset the query so the rest of the page works correctly 
        ?>
      <?php endif; ?>
    <?php endwhile; ?>
  <?php endif; ?>
</div>

If this does not work for you, try this:

<?php global $post; ?>
<?php if( have_rows('vyber_clanku') ): ?>
    <?php while( have_rows('vyber_clanku') ): the_row(); ?>
        <?php $post_object = get_sub_field('clanek'); ?>
        <?php if( $post_object ): ?>
            <?php // override $post
            $post = $post_object;
            setup_postdata( $post );
            ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
            <?php wp_reset_query(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
        <?php endif; ?>
    <?php endwhile; ?>
<?php endif; ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Toggle Table Row with jQuery (usable in Toolset)
31. 12. 2019 in
If you want toggle to open a new row in the table, then you need to use some jQuery with Toolset again. First – create the table (you can use it in view, content tempate, etc.). All credit for this example goes to jsfiddle: http://jsfiddle.net/GqS7W/. And use it with this jQuery script. Do not forget […]
Read More
Aleš Sýkora wrote
Tracking Toolset Forms in Google Analytics with Google Tag Manager
7. 8. 2018 in
What if you want to track your Toolset Forms submissions with Google Analytics Events? See how to do this with Google Tag Manager quickly.
Read More
Aleš Sýkora wrote
Get homepage link as a logo link in Oxygen Builder
Wrap your website’s logo in link wrapper and use this PHP function inside, to create the Home link.
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram