Forums › Forums › Search & Filter Pro › Cache not updated automatically
- This topic has 26 replies, 4 voices, and was last updated 8 years, 4 months ago by
Ross.
-
Ross Moderator(Private) March 2, 2017 at 9:09 pm #94161
Hi
ElliotPablo! (doh!)The post you can see has all the info you really need, previous posts/issues were not related to ACF.
As described above, the issue is, why does
get_post_meta
not work inside asave_post
, when using a frontend ACF form (and, possibly if you have a large(ish) number of that particular post type in your DB already). It works in all other areas of WP where a post is saved (and it works for Sanna, on a version of her site with a low number of posts) unless the post meta is saved separately usingadd_post_meta
– something we also detect and update our cache accordingly, so shouldn’t be an issue there..Could it be something is taking longer save, so when we use
get_post_meta
the processes haven’t finished (I didn’t think this was possible but looking at it as the only thing that kinda makes sense atm).This one is really for the folk over at ACF to answer, I’m happy to jump in on that communication to help things get sorted more quickly (and it might be useful to refer them to this thread).
BTW, I don’t think the
acf/pre_save_post
suggestion will work in this instance, because if a post does not exist, how can you add post meta to it… it might work with existing posts but I doubt it when creating new ones.Hope that helps, get in touch with ACF and let me know what they say.
Best
Ross Moderator(Private) March 3, 2017 at 2:49 pm #94346Ok great news, problem solved (well, we have a workaround)!
I’ve not really used frontend submissions so took a little more time to familiarise myself with it.
I found the acf action / equivalent for
save_post
which isacf/save_post
and looks like (with the correct priority) we can get the save_post action to return the correct meta data.https://www.advancedcustomfields.com/resources/acf-save_post/
So, my solution is to trigger cache update manually when acf/save_post.
Add this to the bottom of functions.php:
function my_acf_save_post( $post_id ) { // bail early if no ACF data if( empty($_POST['acf']) ) { return; } if ((!is_admin()) || (defined('DOING_AJAX') && DOING_AJAX)) { do_action("search_filter_update_post_cache", $post_id); } } add_action('acf/save_post', 'my_acf_save_post', 20);
The
is_admin
line makes sure that the cache is only updated on the frontend and in ajax requests (as we know creating posts in the admin area works fine)The only issue with this approach is on the frontend, S&F will build the cache for a new post twice, first without any meta data, and then on acf/save_post, with the correct data.
It should add very little overhead, but its worth pointing out (I may look into making it easy to remove S&F cache from the the WP
save_post
action, unless of course ACF get the WPsave_post
action working on the front end).Let me know how you get on.
Sanna, I added this to the first site I mentioned that I have been working on and you can see the posts are updating correctly 🙂
Best
Anonymous(Private) March 6, 2017 at 9:34 am #94798Hi Ross,
I must say that you have done a really great job tracking this problem! I’m really greatful for that!
The solution to trigger the cache manually when acf/save_post works great also in my live environment. It’s now running very nicely!
I will have a look on the issue you mentioned about the results per page… thank you for pointing that out.
Again, thank you very much!
Anonymous(Private) March 14, 2017 at 11:50 am #96610Sanna;
I got this from Elliot ACF, Author:
==================
It sounds like the ‘Search Filter PRO’ plugin is only running in the backend. Lots of plugins do this to avoid bloating performance when visitors come to your site (front end).Can you please contact the ‘Search Filter PRO’ devs and ask them if their plugin supports posts created from the front end.
If they do, we can start debugging the issue, but if they don’t, there’s not much I can do from my end.Elliot
==================What should be your answer to this?
I have referred him to this thread.Thanks, Pablo.
Ross Moderator(Private) March 14, 2017 at 1:24 pm #96655Pablo I’ve split this now and closing this thread – https://support.searchandfilter.com/forums/topic/split-split-cache-not-updated-automatically/
-
AuthorPosts