My question is - I have a CPT Post name Company (CF Value - Google) and a Page titled Role (CF V - Engineer). So I want to auto-update with Post published time and date to company post and Role page if published post custom field value match to Google and Engineer.
For example -
A Job Post published at 11:30:21PM, 13/09/2021, has two Custom Fields Title Company and Role which has Google and Engineer values.
Already published CPT Post Company has a post Google Jobs which has similar CF values Google.
Similarly already published page Engineer Jobs which has CF value Engineer.
So my all condition is satisfied because CF value matched, now the code should update Engineer Job (Page), Google Jobs (Post) date and time with recent published post date, time.
Any reference code or help will be appreciated, I want to implement code in my functions.php file.
My Code (Not Working)
function my_cron_schedules($schedules){
if(!isset($schedules["5min"])){
$schedules["5min"] = array(
'interval' => 1*60,
'display' => __('Once every 5 minutes'));
}
if(!isset($schedules["30min"])){
$schedules["30min"] = array(
'interval' => 30*60,
'display' => __('Once every 30 minutes'));
}
return $schedules;
}
add_filter('cron_schedules','my_cron_schedules');
wp_schedule_event(time(), '5min', 'my_hourly_event', $args);
//add_action('init','my_hourly_event');
function my_hourly_event() {
$the_query = get_posts( 'post_type=post' );
foreach($the_query as $single_post) {
$id=$single_post->ID;
$ad_close_date=get_post_meta($id, 'Validdate', true );
if($ad_close_date!=''){
$today=date("j F Y");
if($ad_close_date<$today){
$update_post = array(
'ID' => $id,
'meta_key' => 'Location',
'publish_date' => get_the_time( '', $post->ID ),
'post_type' => 'jobs',
'meta_value' => get_post_meta(get_the_ID(), 'Location',true));
wp_update_post($update_post);
}
}
}
}