Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Using ACF Relationship fields in Custom Filters
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 1 year, 11 months ago.
- AuthorPosts
- April 19, 2021 at 9:53 am #32808
Hello. I am trying to use the Frontend Filters option on my search, and it works great with all fields except a Relationship type field (ACF).
When I choose this type of field in the “Custom Fields” tab it prints the raw serialized data from the db instead of parsing the related posts.
Attached are screenshots of my settings, and the output on the frontend.The ideal is to have a checkbox version of all the posts from the chosen CPT in the acf field settings, allowing multiselect of related posts.
Please let me know what it takes to implement such functionality.Attachments:
You must be logged in to view attached files.April 19, 2021 at 9:54 am #32811Hi,
ACF relationship fields can not be used in the custom field filters, I’m sorry. Unfortunately we can not implement this in the future either, as relationship/flex fields does not store the data to filter by directly, but only references to other objects.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 19, 2021 at 12:05 pm #32818Say I want to implement it on my own, what would you suggest me to do? Are there any hooks I can use to modify the way in which these fields are rendered in the front end or searched in the db?
I started by copying ‘asp-cf-checkboxes.php’ where I plan to parse the serialized data into labels and ID’s. But to use them on a search I would have to modify the query behavior as well. Any suggestions on that?Thanks for the reply.
April 20, 2021 at 9:43 am #32829For the frontend part you can use the filters API. That let’s you create cusom filters or modify existing ones. Then, you can access the generated arguments within the asp_query_args hook, which executes right before the search query. For custom fields the post_meta_filter stores the generated filters.
Best,
The asp_results hook filters the existing search results, where the query arguments are also present.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.