Home Forums Add-ons Repeater Field Get Options repeater meta_value, not dynamically populated select's meta_value Reply To: Get Options repeater meta_value, not dynamically populated select's meta_value

  • I have more or less found a solution… Somehow!

    I switched the dynamic population of the select box around so that it’s using the trail length as the value, as this will never change but the price will, and I need to match the value of the select to one of the repeater sub-fields.

    Here’s how I’m populating the select now:

    function acf_load_duration_and_pricing_field_choices( $field ) {
        // reset choices
        $field['choices'] = array();
        // if has rows
        if( have_rows('options_trail_duration_and_price', 'option') ) {
            // while has rows
            while( have_rows('options_trail_duration_and_price', 'option') ) {
                // instantiate row
                // vars
                $duration = get_sub_field('trail_duration');
                $price = get_sub_field('trail_price');
                // append to choices - this is the bit I've changed
                $field['choices'][ $duration ] = $duration . ' - ' . '£' . $price . 'pp';
        // return the field
        return $field;
    add_filter('acf/load_field/name=duration_and_pricing', 'acf_load_duration_and_pricing_field_choices');

    And now I’m pulling in the trail price through this shortcode:

    if( have_rows('options_trail_duration_and_price', 'option') ): ?>
        <?php while( have_rows('options_trail_duration_and_price', 'option') ): the_row();
    		$optionduration = get_sub_field('trail_duration', 'option');
    		$optionprice = get_sub_field('trail_price', 'option');
    		$duration = get_field('duration_and_pricing')['value'];
    		if( $optionduration == $duration )
    			echo '<span class="YES!">£' . $optionprice . 'pp</span>';

    Matching the select’s value (e.g. ‘2 Days’) with the repeater’s trail_duration value (‘2 Days’), then outputting the trail_price of that associated row, rather than the trail_price stored in the select’s meta_value.

    For some reason in some cases, it’s outputting the price twice, but at this point I’m just glad it’s working in some way!