Using Custom Field information in the single event template

WordPress Event Management, Calendars & Registration Forums Frontend Submissions Using Custom Field information in the single event template

This topic contains 16 replies, has 2 voices, and was last updated by  Stephen Harris 8 years, 7 months ago.

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #18934

    I have two front end submission forms both with custom fields. I would like to display the information in the single event page.

    One of the submission forms has a two dropdowns. The other has a website url.

    On the custom field I selected new meta-key (eo_events_extra) – when I click save and try and select this from the existing list for another field it does not appear.

    I tried to display this using

    echo esc_html( get_post_meta( get_the_ID(), 'eo_events_extra', true ) );
    in the single event template. I can’t get this to work though…

    I would like this to display the custom information in the event details section. Could you give me a hand please? What do I need to paste into the events template and where to get this to work?

    Thanks

    • This topic was modified 8 years, 7 months ago by  Lukas Feddern.
    Lukas Feddern
    #18941

    when I click save and try and select this from the existing list for another field it does not appear.

    The meta key doesn’t really ‘exist’ until an event is created with that meta key. The existing list will only contains keys in use by existing events. There’s nothing wrong in entering the same meta key as a ‘new’ key in multiple fields.

    The following looks correct:

    echo esc_html( get_post_meta( get_the_ID(), 'eo_events_extra', true ) );
    

    You may want to check by first manually adding the custom field to an event and seeing if it appears. Where exactly have entered this?

    Stephen Harris
    #18942

    Hi,

    I have inserted it into single-event.php template.

    I inserted

    echo esc_html( get_post_meta( get_the_ID(), ‘eo_events_extra’, true ) );

    onto line 46 straight after:
    <?php eo_get_template_part(‘event-meta’,’event-single’); ?>

    What do you mean by manually adding it?

    Thanks

    Lukas Feddern
    #18943

    ok, I may be wrong but I should have been adding it to event-meta-event-single.php right?

    so to get it to display in the list only if it exists so I need something like this:

    <?php if( get_the_terms(get_the_ID(),'event-category') ){ ?>
            
  • <?php _e('Categories','eventorganiser'); ?>: <?php echo get_the_term_list( get_the_ID(),'event-category', '', ', ', '' ); ?>
  • <?php } ?>

    right? but what exactly do I need to get the values sorted in eo_events_list metakey to display with their field names only on the events where they were submitted??

    Really appreciate your help thanks

    Lukas Feddern
    #18944

    The template event-organiser/template/single-event.php isn’t used – it’s only there for reference. The plug-in will insert the event meta template into your themes single.php template (for events, of course).

    So you can create your own single-event.php (in your theme) or you can use the event-meta-single-event.php template.

    Stephen Harris
    #18945

    Ok will use the event-meta-single-event.php template but I don’t no what to use for the if statement. Is it something along the lines of:

    <?php if( get_the_terms(get_the_ID(),'eo_events_extra') ){ ?>
    

    <?php _e(‘Dress Code’,’eventorganiser’); ?>: <?php echo esc_html( get_post_meta( get_the_ID(), ‘eo_events_extra’, true ) ); ?>
    <?php } ?>

    In the right direction? I only want the extra field title to show if it was submitted…

    Thanks

    Lukas Feddern
    #18946

    You can use:

    if ( get_post_meta( get_the_ID(), 'eo_events_extra', true ) ) {
       ...
    }
    

    to check if that key has a value for the event, or to check if the event was submitted:

    if ( get_post_meta( get_the_ID(), '_eventorganiser_fes' ) )  {
       ...
    }
    
    Stephen Harris
    #18947

    thanks Stephen, I’m using:

    [removed]
    

    but all I get is white space under the event title.

    Once I can do it once I should be fine but could you let me know where I’m going wrong?

    Thanks

    • This reply was modified 8 years, 7 months ago by  Stephen Harris. Reason: Code removed due to formatting errors
    Lukas Feddern
    #18964

    Hey Stephen,

    Could I get some help with this? Just need help to display a custom field once and I will be able to do it again from there.

    Thanks

    Lukas Feddern
    #18968

    Hi Lukas,

    You’re previous post had the code snippet garbled so I’m going to take an educated guess as to what you intended. (If you need to post a code snippet write/copy it out normally, highlight the entire snippet and click the curly braces code icon).

    It sounds like you had some sort of error in your snippet, but here’s one that should work:

    <?php   
    if ( get_post_meta( get_the_ID(), 'eo_event_extra', true ) ) {
         printf( '<strong>Dress Code:</strong> %s',  esc_html( get_post_meta( get_the_ID(), 'eo_events_extra', true ) );
    } 
    ?>
    
    Stephen Harris
    #18970

    Hi thanks for getting back to me.

    I am inserting the snippet under this code in event-meta-event-single.php

    <?php if( get_the_terms(get_the_ID(),'event-tag') && !is_wp_error( get_the_terms(get_the_ID(),'event-tag') ) ){ ?>
                
  • <?php _e('Tags','eventorganiser'); ?>: <?php echo get_the_term_list( get_the_ID(),'event-tag', '', ', ', '' ); ?>
  • <?php } ?>

    But I still just get whitespace under the event title. I tried a new meta key (eo_dresscode_meta) but it still doesn’t work. What could I be doing wrong? I really need to get this to work!

    Thanks for your help

    • This reply was modified 8 years, 7 months ago by  Lukas Feddern.
    • This reply was modified 8 years, 7 months ago by  Lukas Feddern.
    Lukas Feddern
    #18974

    What do your error logs say, that would give you a line number for the error as well as an explanation.

    Otherwise, it’s not possible for me to say without seeing the code in its entirety – there’s nothing in principle wrong with what you’re describing.

    Stephen Harris
    #18975

    What do your error logs say, that would give you a line number for the error as well as an explanation.

    Otherwise, it’s not possible for me to say without seeing the code in its entirety – there’s nothing in principle wrong with what you’re describing.

    Stephen Harris
    #18978

    hi Stephen,

    I am getting the error

    Parse error: syntax error, unexpected ‘;’ in public_html/wp-content/themes/Pitchildtheme/event-meta-event-single.php on line 79

    this line is:

    printf( 'Dress Code: %s',  esc_html( get_post_meta( get_the_ID(), 'eo_dresscode_meta', true ) );
    

    I don’t get what’s wrong with the semi colon..

    thanks, Stephen.

    Lukas

    Lukas Feddern
    #18979

    You’re missing a closing bracket (for printf() (sorry, this missing from my earlier post) – try adding a ) immediately before the semicolon.

    Stephen Harris
Viewing 15 posts - 1 through 15 (of 17 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.