Support

Home Forums Event Espresso Premium How to fetch the category of the event?

How to fetch the category of the event?

Posted: October 22, 2014 at 4:59 am

Viewing 7 reply threads


Ferdie Santiago

October 22, 2014 at 4:59 am

Hi Guys,

I’m thinking to create a list of events that is related to my post event.
i tried to use this query below, but i cant find how to get the category of the event or the slug.

i actually try to dump the post (var_dump($post)) in order to see all useful infos but still i cant see the category/categoryname that i’ve inserted on the registered events.

Id like to know if theres a way to filter all event that is related to the event in wp_query? is this possible? please help thanks.

i would appreciate if you could get back to me as soonest.
thanks again.

<?php
$atts = array(
‘title’ => NULL,
‘limit’ => 100,
‘css_class’ => NULL,
‘show_expired’ => FALSE,
‘month’ => NULL,
‘category_slug’ => NULL,
‘order_by’ => ‘start_date’,
‘sort’ => ‘ASC’
);
// run the query
global $wp_query;
$wp_query = new EE_Event_List_Query( $atts );

if (have_posts()) : while (have_posts()) : the_post();

the_content();

endwhile; endif;

?>


Josh

  • Support Staff

October 22, 2014 at 8:18 am

Hi Ferdie,

I can suggest taking a look at the espresso_event_categories() template tag located in public/template_tags.php. It returns the event categories for the event.

One suggestion on the query: In this case it may be best to not use the $wp_query global here. Instead use something like this:

$event_tax_query =  new EE_Event_List_Query( $atts );
if($event_tax_query->have_posts())

As an aside, it turns out that WordPress gives you category archives automatically. If you go to {yoursite.com}/event-category/{name-of-category-slug} you’ll see a list of events in one category. You can even add these views to you site’s navigation using the built in WordPress menu manager.


Ferdie Santiago

October 23, 2014 at 12:40 am

Hi Josh,

Thank you for your reply btw i do really appreciate it, one thing is i could not find the espresso_event_categories() template or the public/template_tags.php in event espresso 4,

also the

$event_tax_query = new EE_Event_List_Query( $atts );
if($event_tax_query->have_posts())

can i use some loop here? and display the list of the event that is related to one category?

i really need to fetch the category of one event, to display the some related events for the event.


Dean

October 23, 2014 at 1:30 am

Hi,

The espresso_event_categories function is in the template_tags.php file which is located at /wp-content/plugins/event-espresso-core-reg/public/template_tags.php

You can use that code to display events from a single category, here’s a version of the query that’s more fleshed out https://gist.github.com/joshfeck/e3c9540cd4ccc734e755


Ferdie Santiago

October 23, 2014 at 2:04 am

Hello Dean,

Sorry it was my fault, i was looking at the previous version, yes i have seen the file already template_tags.php and its already working, but it include a tags like .

is there a way to cut or disable the link, and get only the values of the category?

Thank you for your prompt reply, i really appreciate it.


Dean

October 23, 2014 at 3:29 am

Hi,

Sorry the code you linked didn’t come through, can you add it to a pastebin? pastebin.com


Ferdie Santiago

October 23, 2014 at 3:43 am

Hello,

oh sorry.. actually i have been fetched already the category using espresso_event_categories().. my only problem is the functions returns with a link tag, and i only need the string value, is it possible to strip the values that return in order to get the string and exclude the link tag.

$text = espresso_event_categories();
echo strip_tags($text);

i try using this code but its no use at all.

Thank you again.


Ferdie Santiago

October 23, 2014 at 4:53 am

Hi Dean and Josh,
I am done already. i have simulated a solution on how to fix the problem, btw thanks for all the info that you’ve shared.

I still have 2 issues but ill have tp open a new threads for this 😉 i really really appreciate your effort guys for paying attention. thank you very much!

case closed!

Viewing 7 reply threads

The support post ‘How to fetch the category of the event?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso