Hi,
I have a parent post (Today) being automatically generated each day via code in my function file and the "WP Crontrol" plugin which allows me to run cron jobs. I'd like to automatically connect the most recent 2 child posts (Articles) to that parent post upon its generation.
I thought perhaps I could add code from this post here, but I'm stuck.
https://toolset.com/forums/topic/bulk-assign-child-posts-to-parent-post/#post-1247104
Can you assist with this?
This is the code I am currently using:
[code]
//Create Today post with one day interval
add_filter( 'cron_schedules', 'add_cron_interval_one_day' );
function add_cron_interval_one_day( $schedules ) {
$schedules['one_day'] = array(
'interval' => 86400, //# of seconds in 1 day
'display' => esc_html__( '1 days' ),
);
return $schedules;
}
// Schedule Cron Job Event
function custom_cron_job() {
if ( ! wp_next_scheduled( 'one_day_hook' ) ) {
wp_schedule_event( time(), 'one_day', 'one_day_hook' );
}
}
add_action( 'wp', 'custom_cron_job' );
//Insert post action
function create_post_w_random_terms() {
$postdate = $_POST['Y-m-d'];
$post_id = wp_insert_post( array(
'post_type' => 'today', //post type
'post_status' => 'publish',
'post_title' => 'Today - '. date('l, F jS, Y') , //Set this to whatever you want for post title
'post_content' => 'content here', //Same here
));
}
add_action( 'one_day_hook', 'create_post_w_random_terms' );
[/code]
Thanks,
Tim