Forums Forums Search & Filter Pro Cache not updated automatically

Viewing 6 posts - 21 through 26 (of 26 total)
  • Ross Moderator
    #94161

    Hi Elliot Pablo! (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 a save_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 using add_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

    Anonymous
    #94181

    Thanks for your timely response.
    I have contacted them and provided a link to this thread.
    Hope some additional light comes to this issue soon.

    Regards,

    Pablo.

    Ross Moderator
    #94346

    Ok 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 is acf/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 WP save_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
    #94798

    Hi 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
    #96610

    Sanna;

    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
    #96655
Viewing 6 posts - 21 through 26 (of 26 total)