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 9 years, 3 months ago.
-
AuthorPosts
-
September 14, 2015 at 7:48 pm #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 9 years, 3 months ago by Lukas Feddern.
Lukas FeddernSeptember 14, 2015 at 8:47 pm #18941when 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 HarrisSeptember 14, 2015 at 8:59 pm #18942Hi,
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 FeddernSeptember 14, 2015 at 9:15 pm #18943ok, 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 FeddernSeptember 14, 2015 at 9:26 pm #18944The 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 themessingle.php
template (for events, of course).So you can create your own
single-event.php
(in your theme) or you can use theevent-meta-single-event.php
template.Stephen HarrisSeptember 14, 2015 at 9:36 pm #18945Ok 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 FeddernSeptember 14, 2015 at 9:48 pm #18946You 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 HarrisSeptember 14, 2015 at 10:23 pm #18947thanks 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 9 years, 3 months ago by Stephen Harris. Reason: Code removed due to formatting errors
Lukas FeddernSeptember 15, 2015 at 11:14 pm #18964Hey 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 FeddernSeptember 15, 2015 at 11:20 pm #18968Hi 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 HarrisSeptember 15, 2015 at 11:58 pm #18970Hi 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 9 years, 3 months ago by Lukas Feddern.
- This reply was modified 9 years, 3 months ago by Lukas Feddern.
Lukas FeddernSeptember 16, 2015 at 12:59 am #18974What 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 HarrisSeptember 16, 2015 at 12:59 am #18975What 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 HarrisSeptember 16, 2015 at 10:16 am #18978hi 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 FeddernSeptember 16, 2015 at 10:18 am #18979You’re missing a closing bracket (for
printf(
) (sorry, this missing from my earlier post) – try adding a)
immediately before the semicolon.Stephen Harris -
AuthorPosts