Advertisement
clatterblast

Get Event Categories with Event Espresso

Aug 3rd, 2012
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. //this will give you just the last category from the list
  2.  
  3. $sql = "SELECT * FROM " . EVENTS_CATEGORY_TABLE;
  4. $sql .= " ORDER BY category_name ";
  5. $event_categories = $wpdb->get_results($sql);
  6. $num_rows = $wpdb->num_rows;
  7. if ($num_rows > 0) {
  8.     foreach ($event_categories as $category) {
  9.     $category_id = $category->id;
  10.     $category_name = $category->category_name;
  11.     $in_event_categories = $wpdb->get_results("SELECT * FROM " . EVENTS_CATEGORY_REL_TABLE . " WHERE event_id='" . $event_id . "' AND cat_id='" . $category_id . "'");
  12.     foreach ($in_event_categories as $in_category) {
  13.       $this_event_category = $in_category->cat_id;
  14.     }
  15.   }
  16. }  
  17. echo $this_event_category;
  18.  
  19.  
  20. //this will give you all the categories associated with the event
  21.  
  22. $sql = "SELECT * FROM " . EVENTS_CATEGORY_TABLE;
  23. $sql .= " ORDER BY category_name ";
  24. $event_categories = $wpdb->get_results($sql);
  25. $num_rows = $wpdb->num_rows;
  26. if ($num_rows > 0) {
  27.     foreach ($event_categories as $category) {
  28.     $category_id = $category->id;
  29.     $category_name = $category->category_name;
  30.     $in_event_categories = $wpdb->get_results("SELECT * FROM " . EVENTS_CATEGORY_REL_TABLE . " WHERE event_id='" . $event_id . "' AND cat_id='" . $category_id . "'");
  31.     foreach ($in_event_categories as $in_category) {
  32.       echo ' '.$in_category->cat_id;
  33.     }
  34.   }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement