Skip to content

Instantly share code, notes, and snippets.

@viruthagiri
Created May 2, 2016 08:53
Show Gist options
  • Select an option

  • Save viruthagiri/64237ef1093ec4b7612a944b8d80ef23 to your computer and use it in GitHub Desktop.

Select an option

Save viruthagiri/64237ef1093ec4b7612a944b8d80ef23 to your computer and use it in GitHub Desktop.
<?php
function whoop_event_detail_add_tag() {
global $post, $preview;
?>
<dl>
<dt><?php echo __('Tags:', GEODIRECTORY_FRAMEWORK); ?></dt>
<dd><?php
$taxonomies = array();
$post_type = 'gd_event';
if (!empty($post->post_tags)) {
if (taxonomy_exists($post_type . '_tags')):
$links = array();
$terms = array();
// to limit post tags
$post_tags = trim($post->post_tags, ",");
$post_id = isset($post->ID) ? $post->ID : '';
/**
* Filter the post tags.
*
* Allows you to filter the post tags output on the details page of a post.
*
* @since 1.0.0
* @param string $post_tags A comma seperated list of tags.
* @param int $post_id The current post id.
*/
$post_tags = apply_filters('geodir_action_details_post_tags', $post_tags, $post_id);
$post->post_tags = $post_tags;
$post_tags = explode(",", trim($post->post_tags, ","));
foreach ($post_tags as $post_term) {
// fix slug creation order for tags & location
$post_term = trim($post_term);
$priority_location = false;
if ($insert_term = term_exists($post_term, $post_type . '_tags')) {
$term = get_term_by('name', $post_term, $post_type . '_tags');
} else {
$post_country = isset($_REQUEST['post_country']) && $_REQUEST['post_country'] != '' ? sanitize_text_field($_REQUEST['post_country']) : NULL;
$post_region = isset($_REQUEST['post_region']) && $_REQUEST['post_region'] != '' ? sanitize_text_field($_REQUEST['post_region']) : NULL;
$post_city = isset($_REQUEST['post_city']) && $_REQUEST['post_city'] != '' ? sanitize_text_field($_REQUEST['post_city']) : NULL;
$match_country = $post_country && sanitize_title($post_term) == sanitize_title($post_country) ? true : false;
$match_region = $post_region && sanitize_title($post_term) == sanitize_title($post_region) ? true : false;
$match_city = $post_city && sanitize_title($post_term) == sanitize_title($post_city) ? true : false;
if ($match_country || $match_region || $match_city) {
$priority_location = true;
$term = get_term_by('name', $post_term, $post_type . '_tags');
} else {
$insert_term = wp_insert_term($post_term, $post_type . '_tags');
$term = get_term_by('name', $post_term, $post_type . '_tags');
}
}
if (!is_wp_error($term) && is_object($term)) {
// fix tag link on detail page
if ($priority_location) {
$tag_link = "<a href=''>$post_term</a>";
/**
* Filter the tag name on the details page.
*
* @since 1.5.6
* @param string $tag_link The tag link html.
* @param object $term The tag term object.
*/
$tag_link = apply_filters('geodir_details_taxonomies_tag_link',$tag_link,$term);
$links[] = $tag_link;
} else {
$tag_link = "<a href='" . esc_attr(get_term_link($term->term_id, $term->taxonomy)) . "'>$term->name</a>";
/** This action is documented in geodirectory-template_actions.php */
$tag_link = apply_filters('geodir_details_taxonomies_tag_link',$tag_link,$term);
$links[] = $tag_link;
}
$terms[] = $term;
}
//
}
if (!isset($listing_label)) {
$listing_label = '';
}
$taxonomies[$post_type . '_tags'] = wp_sprintf(__('%l', 'geodirectory'), $links, (object)$terms);
endif;
}
if (isset($taxonomies[$post_type . '_tags']))
echo '<span class="whoop-geodir-tags">' . $taxonomies[$post_type . '_tags'] . '</span>';
?></dd>
</dl>
<?php
}
add_action('whoop_event_detail_after_category', 'whoop_event_detail_add_tag');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment