Support

Account

Home Forums Backend Issues (wp-admin) Default values for Repeat Field based on first field

Helping

Default values for Repeat Field based on first field

  • So I have searched around and have yet to find an exact answer for what I’m trying to do. If there is a similar post let me know.

    Basically, I have a repeater field whereby the user selects a specific Taxonomy term, and another field (pricing) appears. I want the default value of the pricing field to modify based on the first field. I can set a default value no problems, but am having issues getting the value of the first field corresponding to the pricing.

    – Pricing Gid repeater
    — Taxonomy term select : pricing_type
    — Text field : pricing

    User selects ‘Small’ for pricing_type, and I would like to populate pricing with the description of the term ‘Small’ as a default. I found that if you make the field conditional on a value being set for the term select then it get’s loaded afterwards. I am just struggling with accessing the data of the first item.

    THANK YOU!!

  • I forgot to post the code that I tried which was

    function abc_acf_set_price( $field ) {
      
      $type = get_field('pricing_type');
      if ($type) {
        $field['default_value'] = field_get('pricing_type');
        return $field;
      }
      return $field;
    }
    add_filter('acf/load_field/name=pricing_details', 'abc_acf_set_price');
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Default values for Repeat Field based on first field’ is closed to new replies.