Update PODS related field on new post

[ad_1]

I have a CPT called “Event” with a related CPT called “Venue”. The Event CPT has a field called “venue” which stores the single value from the Venue drop down list. I am using PHP code to duplicate the event and I am successful in setting the new value for the start date but it is not saving the venue at all. What am I missing?

$eventID = 11395; // id of the event I want to duplicate
$meta = get_post_meta($eventID); // get the meta data from original event which has venue set

// create new event
$new_post = array(
‘post_title’ => get_the_title($eventID),
‘post_content’ => get_post_field( ‘post_content’, $eventID ),
‘post_author’ => get_post_field( ‘post_author’, $eventID ),
‘post_status’ => ‘publish’,
‘post_type’ => ‘event’
);
//save the new post
$pid = wp_insert_post($new_post); //works fine

if ($pid != 0) {
update_post_meta($pid, ‘start_date’, $meta[‘start_date’][0]); // works to update start date
update_post_meta($pid, ‘venue’, $meta[‘venue’][0]); // doesn’t set the venue to be the same
}

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer