Home Forums Add-ons Repeater Field Return all values from a repeater row by using a single dynamic select


Return all values from a repeater row by using a single dynamic select

  • I’ve used a repeater field on the Options page. I want to return all values from a single row within that repeater by using a dynamically populated select box on another page.

    Each repeater row has 4 values. Based on selecting just 1 value ($contactName), I want to return all 4 values in that row on the new page.

    Currently, my code below can only be used to return a single value ($contactRole). What do I need to modify to return all 4 values? The code I used below was based on this ACF article here.

    Thanks for the help!

    // Allow a single contact to be selected from the option page and displayed elsewhere.
    function acf_load_contact_field_choices( $field ) {
        // reset choices
        $field['choices'] = array();
        // if has rows
        if( have_rows('contacts', 'option') ) {
            // while has rows
            while( have_rows('contacts', 'option') ) {
                // instantiate row
                // vars
                $contactName = get_sub_field('contact_name');
                $contactRole = get_sub_field('contact_role');
                $contactEmail = get_sub_field('contact_email');
                $contactImage = get_sub_field('contact_image');
                // append to choices
                $field['choices'][ $contactRole ] = $contactName;
        // return the field
        return $field;
  • This appears to be an acf/load_field filter setting the choices of the other field. What do you mean you want to return all fields in a row? Where to you want to do this? Added to the choices? You’ll need to give more detail on what you want to do and where you want to do it.

  • Good questions – sorry it’s not clearer. I’ve realised that the above code doesn’t need modified. I actually need a new block of code for the page template to display the values from the repeater row.

    I’ll try to explain more clearly:
    – There is a repeater block on the options page. Let’s say they are 10 rows, and each row has 4 values.
    – I want the user to be able to go to Page X, and select 1 of those rows to display on that page.
    – The problem is that I’ve opted to use a dynamically populated select to choose the row (code above). The select is populated with only 1 value, so I’m not sure how to return all 4 values of the row.
    – I’m currently using <?php the_field(‘contact’); ?> to display 1 value on Page X.

    I probably need to do something like.
    – Loop the repeater
    – Based on the $field[‘choices’] selection, only display items which match that row

    Or maybe I’m miles off and shouldn’t be trying to use a select?

    Hopefully this helps explain! Thanks a lot for looking.

  • I realised this approach was dumb and just used a custom post type instead with a post object selector on the page I need it to display on.

Viewing 4 posts - 1 through 4 (of 4 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.