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

  • 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] ';
    }
    ?>
  • 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.