Using ACF Relationship fields in Custom Filters

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 Ernest Marcinko 3 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #32808
    profilesoft70
    profilesoft70
    Participant

    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.
    #32811
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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 :)


    #32818
    profilesoft70
    profilesoft70
    Participant

    Say 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.

    #32829
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    For 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.
    The asp_results hook filters the existing search results, where the query arguments are also present.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.