Support

Account

Home Forums Backend Issues (wp-admin) One section on multiple sub-pages

Solving

One section on multiple sub-pages

  • Hello,

    I have one element – Repeater, which occurs on multiple sub-pages of my website. What do I do, I do not have on every page to enter the same data, only that it was identical for each of them. Pages differ from each other – only one such section is shared.

    Thank you in advance for your help!

  • What version of ACF are you using? Do you have access to adding options pages? I would add an options page and then add the values that are the same on every page to an options page and load those values from there.

  • 4.4.4. Yes, I have access. I would like to achieve such an effect that, for example in the management of subpage “A” I have a repeater. I open subpage “B” and I can get this repeater from subpage “A.

  • Getting the values from another post or page would be difficult, you’d need to know ahead of time what post you want the get the values from, using an options page would be easier.

    In either case you would use an acf/load_field filter http://www.advancedcustomfields.com/resources/acfload_field/

    
    add_filter('acf/load_field/name=repeater_name', 'populate_repeater');
    function populate_repeater($field) {
      // I'm using an options page in this example
      // but you can change $other_post_id to something else
      $other_post_id = 'options';
      if (have_rows('repeater_name', $other_post_id)) {
        $value = array();
        $subfields = array(
          'list',
          'yours',
          'subfields',
          'here'
        );
        while (have_rows('repeater_name', $other_post_id)) {
          the_row();
          $row = array();
          foreach ($subfields as $subfield) {
            $row[$subfield] = get_sub_field($subfield);
          } // end foreach subfield
          $value[] = $row;
        } // end while have rows
        $field['value'] = $value;
      } // end if have rows
      return $field; 
    }
    
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.