Advertisement
BakerMan

TEC 3.x [event_category_link slug="x"] shortcode

Aug 23rd, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. /**
  2.  * Handler for event_category_link shortcode.
  3.  * Usage: [event_category_link slug="my-category-slug"]
  4.  *
  5.  * If the slug is invalid or isn't provided then it will
  6.  * return empty.
  7.  *
  8.  * @param $args
  9.  * @return string
  10.  */
  11. function event_category_link_shortcode($args) {
  12.     // We need TribeEvents to have loaded and a slug to have been passed in
  13.     if (!class_exists('TribeEvents')) return;
  14.     if (empty($args) or !isset($args['slug'])) return;
  15.  
  16.     // Try to load the term, return empty if it can't be found
  17.     $term = get_term_by('slug', $args['slug'], TribeEvents::TAXONOMY);
  18.     if (!$term || !is_object($term)) return;
  19.  
  20.     // Get the link
  21.     $url = TribeEvents::instance()->getLink('upcoming', false, $term->term_id);
  22.     $link = '<a href="' . esc_attr($url) . '"> ' . esc_html($term->name) . ' </a>';
  23.  
  24.     return $link;
  25. }
  26.  
  27. add_shortcode('event_category_link', 'event_category_link_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement