Create function in functions.php with hook name to execute URL

AS said by Fleuv you can use wp_schedule_event() function to execute your code like this add_action(‘my_twfours_action’, ‘my_twfours_action_fn’); my_twfours_action_fn (){ //this code will execute every 24 hours } wp_schedule_event( time(), ‘daily’, ‘my_twfours_action’ ); //adding new cron schedule event To create your 2 minutes filter and then scheduling a cron jo is like function my_two_minutes_filter( $schedules ) … Read more

Cronjob returns a lot of REMOTE_ADDR, SERVER_PORT, SERVER_NAME, etc errors

You’re getting Undefined index errors because you’re loading the files directly and not rendered through the server. The server typically populates those values and it’s actually more secure to run with less elevated privileges (through an HTTP request). Throw your manual cron to a curl or wget — whichever you have installed on your server. … Read more

Force Cron to run only on one server

I would create a constant in the wp_config.php defining which Server you are on. So far so good, not really magic. The tricky part, as you mentioned is to get the cron running for sure, and not aborting if it’s accidentally the wrong server. Try the function like this: function my_cron_callback() { if ( MY_SERVER_SETUP … Read more

Schedule cron event from widget

wp_schedule_event takes a hook as parameter, not a function. Try: wp_schedule_event(time(), ‘daily’, ‘my_daily_event’); add_action(‘my_daily_event’, array(&$this, ‘my_widget_cron’)); if ( !wp_next_scheduled( ‘my_daily_event’ ) ) { wp_schedule_event(time(), ‘hourly’, ‘my_daily_event’) } If you remove the widget from the sidebar, the cron will still continue to run. You can run the following code (outside of the widget class) to clear … Read more

Use Cron to modify posts via sql

Creating your own schedules is a little messy (because they need to be persistent and stored in database), but it is quite easy to hop on one of the native schedules that run twice a day. add_action( ‘wp_version_check’, ‘my_function’ ); function my_function() { //stuff } As for running actual queries you should use $wpdb for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)