In my theme I have a custom post type set up for storing academic publications (publications) which includes custom taxonomy for tagging publications (publication-type).
On my archive template for publications I am setting up a form which allows visitors to search publications (title, year etc). I set up a front end form for the search form using the acf_form function so I could use the taxonomy type field to allow visitors to search by tag (my custom publication-type taxonomy). I was able to successfully load the taxonomy field on the front end.
Without getting into detail when the search form is submitted I don’t need to save any actual data to the database. Instead I am using the ACF pre_save_post filter to check the form field values and save them to the session cookie (where they are later used to query publications on the archive page).
What I am stuck on is how do I retrieve the value of the taxonomy field within the filter function? Basically I need to get the term id and also check to see if the field is null (in the options for the taxonomy field I have the allow null setting enabled).
Hope the above makes sense! Thanks for your help and please get back to me when you have a chance.
I was able to figure this out, turned out to be a simple answer of course! The taxonomy field returns value in an array (for example $_POST[‘acf’][‘field_5b7cf5019f615’]), I was able to use this to retrieve the ID of the term selected.
The search form I outlined above worked out well. I was able to use the pre_save_posts field to store fields values from the form in the session and use them to search my publications archive. I was also able to use the load value filter on the taxonomy field to keep the last term searched selected.
I continue to be impressed with how thorough this plugin is, lots of tools available when you need something somewhat custom like this.