Support

Home Forums Event Espresso Premium EE4: How do add extra fields to the event setup screen?

EE4: How do add extra fields to the event setup screen?

Posted: July 1, 2019 at 11:44 am


mbeede@tracom.com

July 1, 2019 at 11:44 am

Greetings – I need to add a few more items of information to the event setup screen on the wordpress admin back-end. So these extra fields can be filled out as just part of the event setup (not on the registration page, or front-end). I don’t see an easy way to do this – how can I do this?

Thanks, Mark


Josh

  • Support Staff

July 1, 2019 at 11:55 am

Hi Mark,

You can use the existing “Custom Fields” meta box. It works the same way as it does for regular WordPress posts. You’ll find more information about how to use Custom Fields here:

https://wordpress.org/support/article/custom-fields/

Mentioned in the above support article, there are plugins that allow for more customized custom fields, and we recommend the Advanced Custom Fields plugin for this.


mbeede@tracom.com

July 1, 2019 at 12:09 pm

Josh – Forgive me but I don’t see a “Custom Fields” box anywhere on the Event setup page, and I don’t have any posts setup. How/where do I find this meta box? THe info does not explain how to get to this box in the first place.

Thanks – Mark


Josh

  • Support Staff

July 1, 2019 at 12:12 pm

Hi Mark,

It’s there by default, so that’s why the information doesn’t explain how to add it.

If it’s been removed, it can be added back by going to the Screen Options tab (upper right corner of the window) and then checking the box next to “Custom Fields”.


mbeede@tracom.com

July 1, 2019 at 12:18 pm

If I am understanding you correctly there should be a “Custom Fields” option on the EE Event setup page? I don’t see one. I click on Screen Options and it doesn’t appear there either. I would send you a screenshot of what I am seeing but I don’t see a way to add an image to this post. Am I looking in the right place?


Josh

  • Support Staff

July 1, 2019 at 12:23 pm

Hi Mark,

I wonder if your WordPress user account has a restriction that doesn’t allow for working with custom fields. Are you logged into the site with a admin level account that has access to all capabilities?


Josh

  • Support Staff

July 1, 2019 at 12:31 pm

Here’s some more information about access to the Custom Fields meta box:

https://www.role-editor.com/access-to-custom-fields-post-meta/


mbeede@tracom.com

July 1, 2019 at 12:34 pm

Found the issue – If you have ACF plugin installed (which I do) then ACF by default removes the “Custom Fields” option from pages and posts because it assumes you want to use ACF instead. To re-enable this feature you have to add this code snippet to the functions.php file:

add_filter(‘acf/settings/remove_wp_meta_box’, ‘__return_false’);

That’s it – it works. NOW it see what you are talking about.

So I will need to add the 3 new custom fields to every event page I have setup. There is no way to just define them once, and have them added to every Event setup page automatically?

Thanks – Mark


Josh

  • Support Staff

July 1, 2019 at 12:39 pm

You can use Advanced Custom Fields (the plugin) to define them once for event setup pages.

To add them without a plugin involves custom coding e.g.
https://wordpress.stackexchange.com/questions/64939/how-to-add-a-predefined-custom-field-without-using-a-plugin


mbeede@tracom.com

July 1, 2019 at 3:06 pm

So I created 3 new custom fields into a group using ACF. They show up in their own section on the Event setup page (nice). Now in the back-end I need to pull those 3 custom field values. I was hoping they would be in the answers array (hanging off of the registration object) but no. How do I get to the 3 custom field values from my PHP?


Josh

  • Support Staff

July 1, 2019 at 7:38 pm

The custom field values are related to the event, they are not directly related to the registration. ACF provides functions for retrieving custom fields:

https://www.advancedcustomfields.com/resources/the_field/

https://www.advancedcustomfields.com/resources/get_field/

There’s also a native WP function:

https://developer.wordpress.org/reference/functions/get_post_meta/

and you can also access the value as a property of the event post:

https://developer.wordpress.org/reference/functions/get_post_meta/#comment-1894


mbeede@tracom.com

July 3, 2019 at 10:48 am

Josh – So like I stated above I have added 3 new custom fields into a group using ACF. The now display and can be filled out the Event setup page. In my PHP I have the following code:
$addRegistrantArray[‘client_rep_id’] = get_field(“max_client_rep_id”);
$addRegistrantArray[‘product_id’] = get_field(“max_product_id”);
$addRegistrantArray[‘session_id’] = get_field(“max_session_id”);

The fields names are correct. But I am getting empty results back on all 3 of the get_field calls. I tried adding a post id to the get_field calls using:
get_the_id() but that’s coming back empty too.

Then I read something about being inside “the loop” vs being outside “the loop” so I tried this:
while (have_posts())
{
the_post();
$addRegistrantArray[‘client_rep_id’] = get_field(“max_client_rep_id”);
$addRegistrantArray[‘product_id’] = get_field(“max_product_id”);
$addRegistrantArray[‘session_id’] = get_field(“max_session_id”);
}

But that doesn’t work either. Can you tell me what’s missing, or what i am doing wrong?

Thanks – Mark


Josh

  • Support Staff

July 3, 2019 at 11:25 am

Hi Mark,

The current post ID would likely not be correct, because it sounds like this code is running on a page other than the event page.

If you’re trying to get custom fields about the event while during the registration process, you’ll need to get the event ID from the transaction in progress. This is similar to the other topic you posted earlier this week.

$cart = EE_Registry::instance()->SSN->cart();
if ( $cart instanceof EE_Cart ) {
        $transaction = $checkout->transaction;
        if ( $transaction instanceof EE_Transaction ) {
            $registrations = $transaction->registrations();
            foreach ( $registrations as $registration ) { 
                if ( $registration instanceof EE_Registration ) {
                    $event = $registration->event();
                    if ( $event instanceof EE_Event ) {
                        // now you have an $event object to work with
                    }
                }
            }
        }
}


mbeede@tracom.com

July 10, 2019 at 4:01 pm

Josh – Ok I have a EE_Event object now. It has a method called question_groups() that I think I call to get MY question group with my 3 custom fields. I tried passing in an array of 1 element (my question group name “MAX Required Fields”) to question_groups() but that error’ed out. Can you layout some code (or point me to some) that takes me from a EE_Event object, through my question group, down to the actual custom field answers please?

Much appreciated – Mark


Josh

  • Support Staff

July 10, 2019 at 4:29 pm

Hi Mark,

I’m a bit confused by your question because you mention question groups. Are these questions that are being asked on the registration form? If so, you’d get the answers via the registration object.

If it’s the values from the custom fields within the event editor that you’re after, then you could use the get_post_meta() function or similar.


mbeede@tracom.com

July 10, 2019 at 4:49 pm

Sorry, let me clarify. I needed to add 3 custom fields to the Event Setup screen in the EE back-end. I already had ACF so I created a new question group in ACF and added the 3 custom fields. They now show up in a new section in Event Setup. Now I need to pull those field responses in my PHP code and do some processing with them. So I need to know how to get at the custom field values that are entered during Event Setup. You indicated above that it starts with a EE_Event object?


Josh

  • Support Staff

July 10, 2019 at 5:30 pm

If your key name is example_key, then the following WP function should work:

if ( $event instanceof EE_Event ) {
  $example_key = get_post_meta($event->ID(), 'example_key', true);                  
}

or you could use a method provided by Event Espresso:

if ( $event instanceof EE_Event ) {
  $example_key = $event->get_post_meta('example_key', true);
}

or with a function provided by the ACF plugin:

if ( $event instanceof EE_Event ) {
  $example_key = get_field('example_key', $event->ID(), false);
}

The support post ‘EE4: How do add extra fields to the event setup screen?’ 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