Support

Home Forums Event Espresso Premium Using Event Metadata

Using Event Metadata

Posted: August 7, 2020 at 4:15 pm

Viewing 3 reply threads


KGM_Adm

August 7, 2020 at 4:15 pm

Hello,

I am trying to use custom fields to display custom info on events in the [ESPRESSO_EVENTS] list. I set up a one field called “Barcode” and input a value ‘12345’ but I can’t seem to figure out why it wont show for the event.

I have added the following code in content-espresso_events-shortcode.php
Code: <?php get_post_meta($post_id = the_ID(), 'Barcode'); ?>

It displays ‘6332’ on the event in the list. Every event I have has its own number displayed. Does EE4 support this function?


Josh

  • Support Staff

August 7, 2020 at 6:32 pm

Hi,

You can make an adjustment to your code so it’s like this instead:

<?php echo get_post_meta( get_the_ID(), 'Barcode', true ); ?>

or to be safe, with a check for a value:

$keyvalue = get_post_meta( get_the_ID(), 'Barcode', true );
// Check if the custom field has a value.
if ( ! empty( $keyvalue ) ) {
    echo $keyvalue;
}


KGM_Adm

August 10, 2020 at 11:12 am

Thanks, worked perfectly!

I was wondering how I can get the key to show before the value. So I want it to show “Barcode: #####” instead of just the numbers.

Thanks in advance!


Tony

  • Support Staff

August 10, 2020 at 2:42 pm

Rather than just:

echo $keyvalue;

You would have:

echo 'Barcode:' . $keyvalue;

From the above, you are already hardcoding the key so it won’t make much difference in the echo itself.

Viewing 3 reply threads

The support post ‘Using Event Metadata’ 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