Update PODS related field on new post
-
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 fineif ($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
}
- The topic ‘Update PODS related field on new post’ is closed to new replies.