Writing a function for WP Cron to run a SQL command daily

Question

I usually use the events manager in PHP MyAdmin to set up scheduled events but since migrating to WP Engine they do not allow it and I must write a function to use WP Cron instead. What should this look like written as a WP function?

I have the SQL command:

UPDATE wp_postmeta SET meta_value = '4 hours' WHERE wp_postmeta.meta_id = 65138;

I need to run it be recurring, for example

Every Monday at 9am

UPDATE wp_postmeta SET meta_value = '4 hours' WHERE wp_postmeta.meta_id = 65138;

On Tuesday at 9am

UPDATE wp_postmeta SET meta_value = '8 hours' WHERE wp_postmeta.meta_id = 65138;

On Wednesday at 9am

UPDATE wp_postmeta SET meta_value = '4 hours' WHERE wp_postmeta.meta_id = 65138;

On Friday at 9am

UPDATE wp_postmeta SET meta_value = '16 hours' WHERE wp_postmeta.meta_id = 65138;

(I followed this answer firstly with regards to $wpdb but am not very comfortable with it to get it right and it’s possibly out of date.)

0
Daniel McMahon 5 months 0 Answers 36 views 0

Leave an answer