Support

Home Forums Event Espresso Premium Duplicate Event including ACF?

Duplicate Event including ACF?

Posted: May 21, 2020 at 10:07 pm

Viewing 1 reply thread


web@the-collaborative.net

May 21, 2020 at 10:07 pm

Hey there! I’m trying to duplicate an event with ACF fields.

I found this: https://eventespresso.com/topic/hooking-into-the-private-function-_duplicate_event/

And generated this code:

function duplicate_custom_field($new_event, $orig_event) {
//duplicate custom field
$guest = get_post_meta($orig_event->ID(), ‘guest’, true);
if ($guest) {
update_post_meta($new_event->ID(), ‘guest’, $guest);
}

$class_information = get_post_meta($orig_event->ID(), ‘class_information’, true);
if ($class_information) {
update_post_meta($new_event->ID(), ‘class_information’, $class_information);
}

$previous_projects = get_post_meta($orig_event->ID(), ‘previous_projects’, true);
if ($previous_projects) {
update_post_meta($new_event->ID(), ‘previous_projects’, $previous_projects);
}

$additional_information = get_post_meta($orig_event->ID(), ‘additional_information’, true);
if ($additional_information) {
update_post_meta($new_event->ID(), ‘additional_information’, $additional_information);
}

$actor_call_time = get_post_meta($orig_event->ID(), ‘actor_call_time’, true);
if ($actor_call_time) {
update_post_meta($new_event->ID(), ‘actor_call_time’, $actor_call_time);
}

$scene_options = get_post_meta($orig_event->ID(), ‘scene_options’, true);
if ($scene_options) {
update_post_meta($new_event->ID(), ‘scene_options’, $scene_options);
}

}
add_action( 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', 'duplicate_custom_field', 10, 2 );

But it doesn’t seem to work. Can you help me figure out what I’m missing please?

Thank you!


Tony

  • Support Staff

May 22, 2020 at 4:28 am

Hi there,

The forums are not ideal for posting blocks of code, small snippets of a few lines are ok, but the above has multiple formated ' and and , I have no idea if that’s from your code or the forum formatting so we recommend posting blocks of code to something like PasteBin and then posting the link here for us to view.

Other than the formatted quotes, the above code looks fine.

However, something to note is our models have a wrapper for get/update/add_post_meta which saves you haveing to pass the ID around makes it a little easier to follow.

For example:

$guest = get_post_meta($orig_event->ID(), 'guest', true);
if ($guest) {
    update_post_meta($new_event->ID(), 'guest', $guest);
}

Can be swapped out for:

$guest = $orig_event->get_post_meta('guest', true);
if ($guest) {
    $new_event->update_post_meta('guest', $guest);
}

The relevant ID’s are passed internally.

Have you tried adding something like:

var_dump($orig_event);
var_dump($new_event));

To the beginning of that callback to confirm you have both objects when duplicating?

Viewing 1 reply thread

The support post ‘Duplicate Event including ACF?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso