Displaying additional fields

This topic contains 5 replies, has 3 voices, and was last updated by  Stephen Harris 8 years, 10 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #16306

    I’ve added additional fields to the form and they display fine but it’s not clear how to get this information to display on the event page itself. Is there a shortcode or does the template need to be edited?

    Shortcode being used on one page is

    [users_events] 

    (user’s logged in page)
    and

    [eo_events] %event_thumbnail% %event_title% Date & Time: %start{jS M Y}{ g:i:a}%
    Location: %event_venue% [/eo_events] 

    for general view.

    An example field added is an input for website, label website and metakey eventWebsite. Similar inputs added for Facebook and Twitter URLs.

    Dale Bulbrook
    #16335

    Hi Dale,

    The additional fields store data in the selected meta key. So, if you were using a template you could retrieve the value via:

     $value = get_post_meta( $event_id, 'eventWebsite', true );
    

    Note, you will need to define $event_id (usually you can use get_the_ID(), but it will depend on context).

    For the [eo_events] placeholder you can use the %event_custom_field{key}% tag. E.g.

     %event_custom_field{eventWebsite}%
    
    Stephen Harris
    #17172

    Hi Stephen,
    I was looking for the same thing and found this thread, not quite sure i understand your reply though.
    So i have added some extra fields to the submission form and would like to display these items on the events list with [eo_events] shortcode.
    What do i need to do and where?
    Thank you

    Petra Mezei
    #17174

    Hi Petra,

    For each custom field added (i.e. non-event field), you would have selected or created a meta key. This a string identifier for that piece of data for any given event. You can change this in the field’s settings.

    If that key were foobar you can retrieve that data in a template with:

    $value = get_post_meta( $event_id, 'foobar', true );
    

    or, for [eo_events], you can use the placeholder %event_custom_field{key}% tag. E.g.

    %event_custom_field{foobar}%
    

    The key is exactly the key you might use in the custom fields metabox on the event admin page. In deed, that is exactly how the data is being stored.

    Stephen Harris
    #17244

    Hi Stephen,
    Thank you for your reply.
    Sorry it might be a dumb question but where do i place this code? I have no idea:
    $value = get_post_meta( $event_id, ‘foobar’, true );

    I’d also like to display the username and avatar of the user that posted the event. How do i do that?
    Many thanks

    Petra Mezei
    #17256

    Hi Petra,

    While you can use placeholders with the event list shortcode – there aren’t placeholders for username / avatar, so you’ll need to customise the template. See also http://docs.wp-event-organiser.com/shortcodes/events-list/.

    Then, for example, the following will print the event custom field ‘foobar’ wherever it is placed in the template:

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

    Please see the the WordPress codex for details on displaying an avatar and username. You can get the submitter ID via:

     $submitter_id = eo_fes_get_submitted_event_meta( get_the_ID(), 'submitter', true );
    

    which you can use to get the avatar / username. Please not that this assumes the submitter is logged-in (as otherwise they won’t have an ID).

    Stephen Harris
Viewing 6 posts - 1 through 6 (of 6 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.