Support

Account

Home Forums General Issues Filter post object based on selected taxonomy Reply To: Filter post object based on selected taxonomy

  • Using the select2_ajax_data hook in JS you need to get the value of the other field you want to filter by and and add that to the data.

    
    acf.add_filter('select2_ajax_data', function( data, args, $input, field, instance ){
    
        // do something to data
    
        // return
        return data;
    
    });
    

    I don’t really know all the details for using this. I would assume that the current field that the ajax query is being done for will be in field so you would need to check this to see if it is the field you want to change it for.

    I would add the basic script (above) and then I would start using console.log() to start outputting stuff to figure it out.

    Then use acf.Field() to get the value of the field.

    Once you have the data added then you would use an acf/fields/post_object/query filter to alter the query based on the data value you’ve added, This will be in $_GET.