Support

Home Forums Event Espresso Premium add_meta_boxes on admin create/edit event pages (EE – 3, WP – 4.1)

add_meta_boxes on admin create/edit event pages (EE – 3, WP – 4.1)

Posted: February 9, 2015 at 4:49 pm

Viewing 4 reply threads


Invex09

February 9, 2015 at 4:49 pm

I am trying to add a custom meta box but have been unsuccessful. I saw this post (https://eventespresso.com/topic/custom-events-meta-boxes/) and and followed the steps outlined in it but was not able to successfully get the meta box to show on the event page.

In my code below you will see that I tried adding the meta box to the post type “post” (for testing) and “espresso_events”. When it is set as “post” I see the meta box show up (as well as my echo “hotel_info_add_post_meta_boxes”) but not when the type is set to “espresso_events”.

Here is an excerpt of my code in my-theme/functions.php:
add_action( ‘add_meta_boxes’, ‘hotel_info_add_post_meta_boxes’ );

function hotel_info_add_post_meta_boxes()
{
echo “hotel_info_add_post_meta_boxes”;
add_meta_box(
‘hotel-info-post-class’, // Unique ID
esc_html__( ‘Hotel Information’, ‘example’ ), // Title
‘hotel_info_post_class_meta_box’, // Callback function
//’espresso_events’, //Commented out for testing
‘post’, // Inserted for testing.
‘side’, // Context
‘default’ // Priority
);
}

Since the echo doesn’t even appear on the event edit post page, it seems to me that hotel_info_add_post_meta_boxes() is not being run.
– Is the hook is not firing?
– Am I using the wrong hook? (I understand I could also use ‘add_meta_boxes_espresso_events’ but this should work shouldnt it?)
– Is there something else I am missing?
– Is it possible to see the complete innards of a working example of this with EE3?


Dean

February 10, 2015 at 4:16 am

Hi,

The post you linked to doesn’t say this but it is referring to EE4, not EE3.

The reason for this is that EE4 uses Custom Post Types for events, EE3 does not.

This makes adding custom meta boxes to EE3 somewhat difficult. If you look at the /wp-content/plugins/event-espresso/includes/event-management/edit_event.php file for example, you will see that in EE3 we ended up hand coding the “meta boxes” that you see. This is obviously not great and was from legacy code, which is why in EE4 we swapped to the better method of using custom post types.

You could use these action hooks to create your own faux meta box:

action_hook_espresso_new_event_right_column_top (0 params)
action_hook_espresso_edit_event_right_column_top (1 param: $event_id)


Invex09

February 10, 2015 at 7:51 am

Hi Dean, thanks for the reply. That makes a lot more sense with the behavior I am seeing. I will try those hooks.

If the add_meta_boxes hook doesnt work for EE3, is the same true about the ‘save_post’ hook for saving the data that the user enters in this meta box? Is there another pair of hooks for this?


Invex09

February 10, 2015 at 7:58 am

I just found these Event Creation Hooks:

action_hook_espresso_update_event_success
includes/event-management/update_event.php

action_hook_espresso_insert_event_success
includes/event-management/insert_event.php

Are these the hooks I should use to save the data? If not I suppose I could always add a save button to my meta box, right?


Sidney Harrell

February 10, 2015 at 12:13 pm

Yes, I believe your meta boxes should be within the form that submits with the event, so you should be able to add your inputs, and then grab the POST values in your functions on those hooks.

Viewing 4 reply threads

The support post ‘add_meta_boxes on admin create/edit event pages (EE – 3, WP – 4.1)’ 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