Getting custom field values to show category title

Home Forums Ticket Products Event Tickets Plus Getting custom field values to show category title

  • This topic has 9 replies, 2 voices, and was last updated 7 years ago by Christopher.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1253197
    Christopher
    Participant

    Hi there,

    I have the following scenario:

    In our page.php we have something like a slider between our menu and the page content.
    Now we’d like to show the category of an event as a title in this slider. As it has to be written in page.php I don’t think I can use echo tribe_get_event_categories();, or am I wrong?
    So our idea was to set a custom field for each event, give this event the name “category”, set the specific category for this event by hand as the value and then do something like echo get_post_meta(get_the_ID(), ‘category’, true);.
    Unfortunately this doesn’t work, but I don’t know why because on other pages it’s not a problem at all.

    Could you please give me a hint for this?
    Many thanks in advance.

    #1254091
    Nico
    Member

    Hi there Christopher,

    Thanks for getting in touch with us! I can help you here 🙂

    As it has to be written in page.php I don’t think I can use echo tribe_get_event_categories();, or am I wrong?

    Well it depends on which ‘global post’ is set in the place where you use this. You can certainly use tribe_get_event_categories and pass the event ID as the first parameter of the function:

    // $event_id must contain the actual event ID value
    tribe_get_event_categories ( $event_id );

    Please let me know if this works for you,
    Best,
    Nico

    #1256589
    Christopher
    Participant

    First of all many thanks!

    In my page.php I use global $post to get the id of the current page ($page_id = $post -> ID), but this doesn’t work for events.

    I tried to get the category with a self written shortcode and use it in a description of an event, that works. But when I use this shortcode in my page.php it again gets an empty value.

    Where is my fault?

    #1256645
    Nico
    Member

    Thanks for following up Christopher!

    Let’s recap a bit! Events are not rendered by page.php file by default. You can switch this setting in ‘WP-Admin > Events > Settings > Display > Events Template’ by selecting ‘Default Page Template’.

    In my page.php I use global $post to get the id of the current page ($page_id = $post -> ID), but this doesn’t work for events.

    If the above is correctly set then it should work. Are you using this for single event views?

    Please let me know about it,
    Best,
    Nico

    #1260651
    Christopher
    Participant

    Unfortunately, I selected this setting all the time.
    And yes, I use it for single event views.

    When I view a single event I want to display the category in the header, that’s all.
    I tried following in page.php, but didn’t work because $page_id is always emmpty for events.

    <?php
    global $post;
    $page_id = $post->ID;
    ?>
    <h1 class="post-title"><?php tribe_get_event_categories ( $event_id ); ?></h1>
    #1266775
    Nico
    Member

    Thanks for the follow-up Christopher and sorry for the delay in my reply. I’m still catching up with things after our annual team trip.

    I could verify what you are experiencing, and found a workaround 🙂

    In page.php (even outside the loop) this should work for you:

    echo tribe_get_event_categories ( $wp_query->queried_object->ID );

    Please let me know if it does,
    Best,
    Nico

    #1267470
    Christopher
    Participant

    Oh yes, perfect!

    Thank you very much, you made my day/week! 😀

    Btw – your whole support for the Modern Tribe products is really good.

    Best regards!

    #1267887
    Nico
    Member

    Woooot! Stoked to hear Christopher 🙂

    Thanks for the kind words about our service, I’ll share it with the rest of the team!

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Best,
    Nico

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Getting custom field values to show category title’ is closed to new replies.