Support

Account

Home Forums Add-ons Repeater Field Store acf repeater value and use it outside the loop

Helping

Store acf repeater value and use it outside the loop

    • danilab

    • October 1, 2020 at 4:28 am

    I was wondering if there is a way to store data from a repeater and use it outside the loop?
    At the moment I’m only able to print the last value from the repeater.

    This is the code snippet I’m using.

    <?php foreach( $posts as $post):
       $parents_cat_list = get_the_terms($post->ID, 'ingredients_categories', array( 'parent' => 0 ) );
      $values = array();
    ?>
    <?php setup_postdata($post); ?>
    <?php
    $value = get_field('link');
    if (!in_array($value, $values)) {
      $values[] = $value;
    }
    ?>
    <?php endforeach; ?>
    <?php wp_reset_postdata(); ?>

    and then outside the loop

    <?php foreach ($values as $value) {
      echo ' [START] ' . $value .' [FINISH] ';
    }
    ?>
    • danilab

    • October 1, 2020 at 4:04 pm

    The snippet above is the relationship that sits under repeater. My current structure looks like this ingredients=repeater/items=repeater/ingredient_name=relationship. Ingredient_name has a field “link” this is what I want to store and use outside the loop as it will need to turn into Amazon asin link.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.