Support

Account

Home Forums Backend Issues (wp-admin) Select sibling field inside select2_ajax_data filter Reply To: Select sibling field inside select2_ajax_data filter

  • Found a solution:

    JS

    acf.add_filter('select2_ajax_data', function(data, args, $input, field){
      const post_type_field = acf.findFields({
        name: 'post_type',
        sibling: field,
        limit: 1,
      });
      const post_type_value = post_type_field.find($('select')).val();
    
      if (post_type_value) {
        data.post_type = post_type_value;
      }
    
      return data;
    });

    PHP

    add_filter('acf/fields/post_object/query/name=featured_posts', function($args){
        if (!empty($_POST['post_type'])) {
            $args['post_type'] = esc_attr($_POST['post_type']);
        }  
     
        return $args;
    });