I'm attempting to regularly update a custom field ($company_rating) in a CPT with update_post_meta(). The cronjob is assigned and working. I've tested the function and it prints correctly (I've shortened it here for readability). But the fields are not updating.. Any ideas?
function update_company_ratings_test() {
global $post;
$comp_args = array(
'post_type'=>'boat-company',
'posts_per_page'=>'-1',
'post_status '=> 'publish',
);
$posts_array = get_posts( $comp_args );
if ($posts_array) {
foreach( $posts_array as $post_id ){
setup_postdata($post);
$company_id = $post_id->ID;
$company_rating = 42;
update_post_meta( $company_id, 'company_rating', $company_rating, true );
}
}
wp_reset_postdata();
}
add_action( 'update_cron_test', 'update_company_ratings_test' );
if( !wp_next_scheduled( 'update_cron_test' ) ) {
wp_schedule_event( time(), 'hourly', 'update_cron_test' );
}