Forums › Forums › Search & Filter Pro › Cache not updated automatically
- This topic has 26 replies, 4 voices, and was last updated 7 years, 8 months ago by Ross.
-
Anonymous(Private) March 2, 2017 at 9:00 pm #94155
Hi guys;
It seems i’m having the same problem. I’m also using acf_form.
Apart from turning off the use transients setting, is there anything else that needs to be done?
A few posts in this thread are marked as private, so i’m not sure if following the right directions.Conditions seems the same in my case, im using acf_from and we have currently more than 500 items.
In fact i have filed a ticket in ACF recently with an issue that may be hinting at what is possibly happening. I know this is not directly related to SF&P but it looks definitively related:
Pablo Liz sent a message:
Feb 22, 10:06am
Last Author Edited by is not being updated when using frontend forms.
It seems i have all required things in the page for it to work. Even repeater fields with media files are working ok including frontend javascript. Having used it in production with more than 40 fields of all types this is so far the only problem i’ve found regarding the front-end form.This works normally when using the backend. In our case this is a critical function. Is this a bug or anything specific i should be looking at?
i have…
<?php acf_form_head(); ?> <?php get_header(); ?> ... acf_form(array('id'=>'my_frontend_form_id','label_placement' => 'left')) ... <?php acf_enqueue_uploader(); ?> <?php get_footer(); ?>
I saw another post about revisions not being created when using frontend forms. Maybe its related to that?
—- Versions —-
ACF v5.5.8
WP v4.7.2And, here is the response from the plugin Authors:
Hi Pablo
Thanks for the email.
It looks like the ‘_edit_last’ meta is not updated via WP during the ‘update_post()’ function and is manually called by WP during it’s save_post action.
I’m happy to consider adding this into the acf_form_head() function, but am not sure it would always be desireable.
For now, you could easily use the ‘acf/pre_save_post’ filter to run the following code from WP:
// Update last edit user update_post_meta( $post_id, '_edit_last', get_current_user_id() );
Thanks,
ElliotRoss Moderator(Private) March 2, 2017 at 9:09 pm #94161Hi
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