• Resolved jamiepantling

    (@jamiepantling)


    Is there a way to schedule a “delete and reindex” daily? The post type I’m using TS has an expiry date which should make them disappear from results, but it doesn’t cause a reindex when it passes. However, they do disappear when I delete and reindex.

    I’d like to schedule it every day at midnight, for example. Is there some hook i can use or something?

Viewing 1 replies (of 1 total)
  • Plugin Contributor Sachyya

    (@sachyya-sachet)

    Hello @jamiepantling ,

    You would have to run a cron job to do it automatically at midnight.

    You can try something like this:

    // Schedule the event when WordPress initializes
    add_action('wp', 'schedule_CMTypesenseBulkImport');
    
    function schedule_CMTypesenseBulkImport() {
    	// Check if the scheduled event already exists
    	if (!wp_next_scheduled('run_CMTypesenseBulkImport')) {
    		// Schedule the event to run daily at midnight
    		wp_schedule_event(strtotime('midnight'), 'daily', 'run_CMTypesenseBulkImport');
    	}
    }
    
    // Hook your function to the scheduled event
    add_action('run_CMTypesenseBulkImport', array( Admin::getInstance (), 'CMTypesenseBulkImport') );
Viewing 1 replies (of 1 total)
  • The topic ‘Delete and Reindex regularly’ is closed to new replies.