Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro “Explode” custom field into several records on the cache table

Tagged: 

Viewing 8 posts - 1 through 8 (of 8 total)
  • Diogo Comprido
    #265177

    We have a custom field with several values separated by “|”, like this:

    Post A: “Z”
    Post B: “X | Y”

    We are filtering by this field and, obviously, we get the two options on the select: “Z” and “X | Y”, but we would like it to be “Z”, “X” and “Y”.

    Is there any way we can hook into the cache building process, and manipulate the data so that we insert two records for “Post B” for that custom field?

    Trevor Moderator
    #265219

    There is not, sorry. You have a custom field (post meta) that contains an unordered list with each value separated by |? I am sorry, but our plugin cannot break that list down into individual elements in our cache table (which means it could not be searched from a drop down list).

    The data would have to be correctly converted in to a serialized form. For example, Advanced Custom Fields allows you to create multi-value fields stored in this way, and we do support fields made by ACF of this type.

    Diogo Comprido
    #265269

    Hi Trevor,

    I see in class-search-filter-post-cache.php, lines 2071 to 2092, you indeed check if the value is a serialized array and then add it to the cache accordingly: for each array element or the single value.

    So, I’m wondering if you could add a filter after line 2074 so we could take our single value and explode it into an array? This would not have any effect on current users that do not hook into that filter.

    As a matter of fact, I did it and it works:

    $post_custom_data = apply_filters( 'search_filter_post_cache_post_custom_data', $post_custom_data, $postID, $meta_key );

    https://snipboard.io/A6Efs0.jpg

    I then added this to my own code and I successfully split the values into an array and use them as individual values for filtering:
    https://gist.github.com/webdados/9469b44361ef5ac64e8996c2b533c05f

    Before rebuilding the cache:
    https://snipboard.io/9Owq80.jpg

    After rebuilding the cache (with the filter on your plugin and our code in our theme functions.php file):
    https://snipboard.io/uG9zkR.jpg

    So, we just need you to add the filter to the next update of the plugin.
    Is this possible? 🙂

    Trevor Moderator
    #265276

    I have referred your request to the plugin developer, Ross, for his input.

    Ross Moderator
    #266863

    Hi Diogo

    Apologies for the late reply, I’ve been thinking about how to answer this one.

    Essentially, we’re trying not to add anything new to S&F v2.x – because we’re trying to finish v3.

    I will say, I’d be happy to add this to v3, when it arrives, I think before then there will only be a couple of 2.x releases (which you will have to manage manually, and patch)

    And then we can discuss what changes will need to be made in the new framework.

    I’ve tagged this post as v3 but do feel free to give me a reminder nearer the time.

    Best

    Diogo Comprido
    #266902

    Hi there Ross,

    I understand your developing cycles and agree no major changes should be included, but taking into consideration that:

    1) This a 100% non-breaking change (it’s a filter and it has no impact unless a developer actually hooks into it)

    2) It’s not a good idea to manually patch a plugin after update (I just did it this time to prove the concept that it works)

    3) We’ll probably take a while to update to v3 (due to extreme customization on our filter) but would like to keep v2 updated with the further couple of releases.

    I kindly ask you to reconsider and add this filter to the code.

    Ross Moderator
    #267893

    Hi Diogo

    I’ve added it (not sure when the next version is released, probably just before WP 5.6)

    I changed the name though:

    search_filter_post_cache_build_meta_data

    Best

    Diogo Comprido
    #272340

    Thanks. You can close this ticket.

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

The topic ‘“Explode” custom field into several records on the cache table’ is closed to new replies.