Support

Home Forums Event Espresso Premium Calling a list of all event categories

Calling a list of all event categories

Posted: November 7, 2013 at 2:45 am


Zoe E

November 7, 2013 at 2:45 am

Hi, is there a way to call a list of all event categories? I want to automatically call all event categories and then assign a custom URL to them (ie /events/?cat=catname) that will automatically load a page of all applicable events (I have that bit covered).

Any ideas on how we can call the list of cats please?


Dean

November 7, 2013 at 2:50 am

Hi Zoe,

The only way to grab all the categories would be via an SQL query:

global $wpdb;
		
		//Get the categories
		$sql = "SELECT * FROM " . EVENTS_CATEGORY_TABLE;
		$categories = $wpdb->get_results($sql);
  • This reply was modified 10 years, 6 months ago by  Dean. Reason: edited code


Zoe E

November 7, 2013 at 10:15 am

Cheers, I’ve done that. Here’s my code incase it’s useful to anyone else:

In functions.php:
function get_event_cats() {
global $wpdb;

$use_sql = “SELECT * FROM wp_events_category_detail”;
$thecats = $wpdb->get_results($use_sql);

$output = $output.”<ul class=\”menu-categories\”>”;
foreach ($thecats as $cat) :
$output = $output.”category_name.”\”>”.$cat->category_name.”“;
endforeach;
$output = $output.””;

return $output;
}

I then created a new page template (page-event-cat.php), assigned it to a new page and place the following in the template (mine is outside the “while” for the page content):

<?php echo do_shortcode(‘[EVENT_ESPRESSO_CATEGORY event_category_id=”‘.$_GET[‘catname’].'”]’); ?>


Dean

November 8, 2013 at 1:45 am

Hi,

Thanks for sharing your code. For future readers, please note it is probably best to use

"SELECT * FROM " . EVENTS_CATEGORY_TABLE;

rather than

“SELECT * FROM wp_events_category_detail”;

As your database may not use the wp_ prefix.


Zoe E

November 8, 2013 at 1:57 am

Well spotted! Or I would normally use $wpdb->prefix to call the table prefit ahead of the table name. Is EVENTS_CATEGORY_TABLE a variable built in to event espresso? Is there a list of these anywhere for future reference?

Cheers 🙂


Josh

  • Support Staff

November 8, 2013 at 7:11 am

Yeah, all of Event Espresso’s database tables are defined in espresso.php. If you look on line 246 in the current version you’ll see all them defined there.

The support post ‘Calling a list of all event categories’ 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