Forums › Forums › Search & Filter Pro › “Explode” custom field into several records on the cache table
Tagged: V3
- This topic has 7 replies, 3 voices, and was last updated 3 years, 10 months ago by Anonymous.
-
Anonymous(Private) November 3, 2020 at 5:26 pm #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(Private) November 4, 2020 at 8:39 am #265219There 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.
Anonymous(Private) November 4, 2020 at 1:10 pm #265269Hi 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/9469b44361ef5ac64e8996c2b533c05fBefore rebuilding the cache:
https://snipboard.io/9Owq80.jpgAfter rebuilding the cache (with the filter on your plugin and our code in our theme functions.php file):
https://snipboard.io/uG9zkR.jpgSo, we just need you to add the filter to the next update of the plugin.
Is this possible? 🙂Ross Moderator(Private) November 18, 2020 at 9:51 am #266863Hi 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
Anonymous(Private) November 18, 2020 at 11:02 am #266902Hi 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(Private) November 26, 2020 at 10:09 am #267893Hi 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
-
AuthorPosts