• Resolved nointelligentlife

    (@nointelligentlife)


    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
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    • Is your venue field a relationship field?
    • What storage type are you using for your event pod?
    • If it’s using meta storage, what is the value of $meta['venue'][0] right there when you are using it?
    • You might try enabling “Watch WP Metadata calls” and “Override WP Metadata values” in Pods Admin > Settings > Performance if you absolutely need to update the relationship from update_post_meta() but I recommend not doing that and doing the following option./li>
    • Alternatively, to set the relationship the correct way, you would want to use a Pods object. If you only need to update one field, then this would be the easiest one-line code you could use for that: pods_field_update( 'your_pod_name', $item_id, 'your_field_name', 'your_field_value' ); otherwise you would use this: https://docs.pods.io/code/pods/save/
    Thread Starter nointelligentlife

    (@nointelligentlife)

    Hi Scott, thanks for the quick reply.

    I have got it to work using your suggestion of $pod->save()

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.