wp_schedule_event – function won’t execute
add_action(‘opbs_update_counts’, array(‘cronTaskUpdateCounts’)); should be add_action( ‘opbs_update_counts’, array( $this, ‘cronTaskUpdateCounts’ ) );
add_action(‘opbs_update_counts’, array(‘cronTaskUpdateCounts’)); should be add_action( ‘opbs_update_counts’, array( $this, ‘cronTaskUpdateCounts’ ) );
You need to schedule the event differently. In your approach, you hook to wp to schedule the event, meaning that it is called everytime WordPress is called, setting your option back. I am not quite sure if the schedule is postponed or if you create multiple schedules this way, but it is not correct. You … Read more
There is a plugin called WP-Cron Control to check your scheduled events. Other way to check it is using WP-CLI via command-line, using this command: wp cron event list Hope this helps!
Your code for scheduling event isn’t correct, here is the correct one: function hits_set_zero_schedule() { if ( ! wp_next_scheduled( ‘hits_set_to_zero’) ) wp_schedule_event( time(), ‘daily’, ‘hits_set_zero’ ); } add_action( ‘wp’, ‘hits_set_zero_schedule’ ); function hits_set_zero_func() { delete_post_meta( $post_id, ‘post_views_count’, true ); } add_action( ‘hits_set_zero’, ‘hits_set_zero_func’ ); Also, you can define intervals otherwise than daily by adding a … Read more
wp_schedule_single_event‘s $timestamp is the time you want the event to occur. This must be in a UNIX timestamp format. WP cron uses UTC/GMT time, not local time. Use time(), which is always GMT in WordPress. time() number of seconds since the Unix Epoch If you want to add a day, you need to add seconds: … Read more
i got this proplem with hight load in my wppit.com so i checked my cpanel and i found the cronjob casue this hiegh load and because WordPress has to work on all sort of different platforms, OS’s and configurations, it can’t rely that there will be a cronjob service on the server that can handle … Read more
For instance, since the configured cron tasks will only be run on page load, the task might not be run at the desired interval if there are no visitors. To prevent this, you need to use your operating system’s task scheduler. For this, you need to define define(‘DISABLE_WP_CRON’, true); in your wp-config.php file. After that, … Read more
As Nathan has said in his comment above, the update_events() function needs to be a public function, not a private function: public scope to make that variable/function available from anywhere, other classes and instances of the object. private scope when you want your variable/function to be visible in its own class only. protected scope when … Read more
define(‘DISABLE_WP_CRON’, true); This line disables the default behaviour of WP Cron. Which is being triggered by a user that visits the site. This is bad for a couple of reasons (nobody might visit, tasks are started via apache handler instead of PHP CLI, …). Now, if you have disabled it, you need another way to … Read more
You can use Function Reference/set post type <?php $post_id = 15; if ( set_post_type( $post_id, ‘page’ ) ) { echo “Post #$post_id is now a Page”; } else { echo “Impossible to transform this post into a page”; } ?>