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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.