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.
-
AuthorPosts
-
March 13, 2017 at 12:47 am #1253197ChristopherParticipant
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.March 14, 2017 at 2:41 pm #1254091NicoMemberHi 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,
NicoMarch 20, 2017 at 12:59 am #1256589ChristopherParticipantFirst 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?
March 20, 2017 at 6:41 am #1256645NicoMemberThanks 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,
NicoMarch 28, 2017 at 12:48 am #1260651ChristopherParticipantUnfortunately, 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>
April 7, 2017 at 1:30 pm #1266775NicoMemberThanks 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,
NicoApril 10, 2017 at 2:39 am #1267470ChristopherParticipantOh 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!
April 10, 2017 at 12:59 pm #1267887NicoMemberWoooot! 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 -
AuthorPosts
- The topic ‘Getting custom field values to show category title’ is closed to new replies.