So I have a function that is called by the wp_schedule_event (cron job) once daily. The goal of the function is to set all posts with a field wpcf-engine-days-to-go
that has a value of "0"
to a draft.
It isn't working, and I suspect the problem is with my SQL. I'm referencing meta values that aren't in the row (or table) of wp_posts. How do I reference wp_meta table in connection with wp_posts?
register_activation_hook(__FILE__, 'tdengine_my_activation');
add_action('tdengine_my_daily_event', 'tdengine_do_this_daily');
function tdengine_my_activation() {
wp_schedule_event(time(), 'daily', 'tdengine_my_daily_event');
}
function tdengine_do_this_daily() {
global $wpdb;
$query = "UPDATE `" . $wpdb->prefix . "posts` SET `post_status`=`draft` WHERE `meta_key` = 'wpcf-engine-days-to-go' = 0 ";
$wpdb->query($query);
}
register_deactivation_hook(__FILE__, 'tdengine_my_deactivation');
function tdengine_my_deactivation() {
wp_clear_scheduled_hook('tdengine_my_daily_event');
}