Run function in to the wordpress plugin with real Cron job

I write wordpress plugin .. That plugin have function (Following code)..

I want run function with real Cron job no Wp corn

Read More

First I deactivate wordpress cron with follwoing code

define('DISABLE_WP_CRON', true);

Then add follwoing code to my host cron

wget -q -O - http://kharidsanj.ir/wp-cron.php?doing_wp_cron >/dev/null 2>&1

And Now I want run following function with real Cron job command

function import_into_db(){

////My code

}

How Can I?

Related posts

Leave a Reply

1 comment

  1. If you are running wp-cron.php on host cron, Use the below code. It worked for me.

    add_filter('cron_schedules','cliv_cron_add_syncdays');
    function cliv_cron_add_syncdays($schedules){
       $schedules['syncdays'] = array(
           'interval' => (86400),
           'display'=> 'Sync Days'
       );
       return $schedules;
    }
    
    add_action('init','cliv_create_recurring_schedule');
    add_action('cron_action','cron_function');
    
    function cron_function(){
       import_into_db(); // your desired function
    }
    
    function cliv_create_recurring_schedule(){
      if(!wp_next_scheduled('cron_action'))
       wp_schedule_event (time(), 'syncdays', 'cron_action');
    }