Support Forums

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

Forums Forums Search & Filter Pro Update Cache after WP All Import

Viewing 10 posts - 1 through 10 (of 13 total)
  • Scott Thome
    #251016

    I have searched this forum and have tried several recommendations (https://support.searchandfilter.com/forums/topic/not-showing-all-results-2/) without any luck. Here’s my setup: WP All Import is importing data on an hourly basis. In the import settings, I have “Increase speed by disabling do_action calls in wp_insert_post during import” checked which means ‘transition_post_status’, ‘save_post’, ‘pre_post_update’, ‘add_attachment’, ‘edit_attachment’, ‘edit_post’, ‘post_updated’, ‘wp_insert_post’ are not being fired. I know that is why Search & Filter’s cache is not being updated. If I manually update cache, then search results are updated.

    As a solution, I’m trying to get wp-cron to update Search & Filter’s cache, but it’s not working either. Is there an error in my code?

    add_action( 'save_to_cache_schedule', 'save_to_cache' );
    function save_to_cache() {
        $args = array(
            'post_type' => 'property',
            'posts_per_page' => -1,
            'fields' => 'ids',
            'cache_results' => false,
            'no_found_rows' => true
        );
        $posts = new WP_Query( $args );
        foreach( (array)$posts->posts as $post_id ) {
            do_action('search_filter_update_post_cache', $post_id);
        }
    }
    add_action( 'init', 'register_save_to_cache_schedule');
    function register_save_to_cache_schedule() {
        if( !wp_next_scheduled( 'save_to_cache_schedule' ) ) {
            // Schedule the event
            wp_schedule_event( time(), 'twicehourly', 'save_to_cache_schedule' );
        }
    }
    add_filter( 'cron_schedules', 'cron_interval_twice_hourly' );
    function cron_interval_twice_hourly( $schedules ) {
        $schedules['twicehourly'] = array(
                'interval'  => 1800,
                'display'   => 'Twice Hourly'
        );
        return $schedules;
    }

    I have tried triggering the do_action(‘search_filter_update_post_cache’, $post_id); function in my theme’s functions.php file, in WP All Import’s function editor, and now in a scheduled function. Any help would be super appreciated!

    Trevor Moderator
    #251060

    I would try triggering the updates to the cache later (the 1000 in this code):

    add_action('pmxi_saved_post', 'wp_all_import_post_saved', 1000, 1);
    
    function wp_all_import_post_saved($id) {
        do_action('search_filter_update_post_cache', $id);
    }

    I do not think you can trigger our full cache rebuild using a cron job.

    If you have an array of all the post IDs affected by the update, you could write some code to loop through that array after the bulk import, triggering the update per post.

    That would require you have available such an array, but I am guessing you could do that.

    Trevor Moderator
    #251062
    This reply has been marked as private.
    Scott Thome
    #251246

    I turned off my cron and put your code in my functions.php file. This was something I tried before, and after another test, newly imported posts are not getting added to cache. There were no errors in the error_log. Any other ideas or thoughts on how I can continue debugging this?

    Trevor Moderator
    #251303

    I have referred this question to the plugin developer, Ross, for his input.

    Scott Thome
    #251318

    That’s awesome, I really appreciate it. Search & Filter is hands-down the best feature of the website, and I’d love to get it playing nicely with WP All Import.

    Ross Moderator
    #251454

    Hi Scott

    This issue has come up from time to time, while I have never been able to replicate it myself… Some users’ have reported a conflict with another plugin while other have managed to mystically resolve themselves…

    I think at this point, we need to be able to reproduce your issue, with the minimum amount of configuration / setup.

    Are you able to setup a staging / dev / test site, with your site stripped back to only essential content / plugins – while the issue still presents itself?

    Thanks

    Scott Thome
    #252069

    I setup a staging environment and did some testing, and it may be related to Hummingbird Pro, which is a caching plugin. When I deactivate that plugin and run another import, new posts are added to Search & Filter’s cache and pull up on the frontend search.

    I have not begun to test with Hummingbird Pro back on, but the plugin does offer URL and template file exclusions from their caching. Do you have experience with Hummingbird Pro and how to use it and Search & Filter together?

    Ross Moderator
    #252099

    Hi Scott

    Thanks for the update, I actually use Hummingbird Pro on a couple of sites (that don’t need S&F) – so will see if I can do some testing with that and figure out the cause / a way to set this up.

    If you can let me know though, by simply enabling the plugin again and re-running the import, if that then breaks things again?

    Best

    Scott Thome
    #253234

    I did some more testing, and Hummingbird Pro does not seem to be the issue. Whether the plugin is on or off, new posts will be added to Search & Filter’s cache if I manually run a WP All Import import. Using the code above works as intended. However, I’m running WP All Import on a cron. When the import is finished via the cron, new posts are not added to Search & Filter’s cache.

Viewing 10 posts - 1 through 10 (of 13 total)

You must be logged in to reply to this topic.