Function Reference: geodir_cpt_categories_output
Summary
Get the cpt categories content.
Global Values
- $post
- (object) (required) The post object.
- Default: None
- $gd_use_query_vars
- (bool) (required) If true then use query vars to get current location terms.
- Default: None
Parameters
- $params
- (array) (required) An array of cpt categories parameters.
- Default: None
Return Values
- (string)
- CPT categories content.
Change Log
Since: 1.5.4
1.6.6 New parameters $no_cpt_filter &no_cat_filter added.
Filters
‘geodir_custom_sort_cpt_terms’ [Line: 442]
‘geodir_category_term_link’ [Line: 470]
Source File
geodir_cpt_categories_output() is located in geodirectory-widgets/geodirectory_cpt_categories_widget.php [Line: 318]
Source Code
function geodir_cpt_categories_output($params) { global $post, $gd_use_query_vars; $old_gd_use_query_vars = $gd_use_query_vars; $gd_use_query_vars = geodir_is_page('detail') ? true : false; $args = wp_parse_args((array)$params, array( 'title' => '', 'post_type' => array(), // NULL for all 'hide_empty' => '', 'show_count' => '', 'hide_icon' => '', 'cpt_left' => '', 'sort_by' => 'count', 'max_count' => 'all', 'max_level' => '1', 'no_cpt_filter' => '', 'no_cat_filter' => '', ) ); $sort_by = isset($args['sort_by']) && in_array($args['sort_by'], array('az', 'count')) ? $args['sort_by'] : 'count'; $cpt_filter = empty($args['no_cpt_filter']) ? true : false; $cat_filter = empty($args['no_cat_filter']) ? true : false; $gd_post_types = geodir_get_posttypes('array'); $post_type_arr = !is_array($args['post_type']) ? explode(',', $args['post_type']) : $args['post_type']; $current_posttype = geodir_get_current_posttype(); $is_listing = false; $is_detail = false; $is_category = false; $post_ID = 0; $is_listing_page = geodir_is_page('listing'); $is_detail_page = geodir_is_page('detail'); if ($is_listing_page || $is_detail_page) { $current_posttype = geodir_get_current_posttype(); if ($current_posttype != '' && isset($gd_post_types[$current_posttype])) { if ($is_detail_page) { $is_detail = true; $post_ID = is_object($post) && !empty($post->ID) ? (int)$post->ID : 0; } else { $is_listing = true; if (is_tax()) { // category page $current_term_id = get_queried_object_id(); $current_taxonomy = get_query_var('taxonomy'); $current_posttype = geodir_get_current_posttype(); if ($current_term_id && $current_posttype && get_query_var('taxonomy') == $current_posttype . 'category') { $is_category = true; } } } } } $parent_category = 0; if (($is_listing || $is_detail) && $cpt_filter) { $post_type_arr = array($current_posttype); } $post_types = array(); if (!empty($post_type_arr)) { if (in_array('0', $post_type_arr)) { $post_types = $gd_post_types; } else { foreach ($post_type_arr as $cpt) { if (isset($gd_post_types[$cpt])) { $post_types[$cpt] = $gd_post_types[$cpt]; } } } } if (empty($post_type_arr)) { $post_types = $gd_post_types; } $hide_empty = !empty($args['hide_empty']) ? true : false; $max_count = strip_tags($args['max_count']); $all_childs = $max_count == 'all' ? true : false; $max_count = $max_count > 0 ? (int)$max_count : 0; $max_level = strip_tags($args['max_level']); $show_count = !empty($args['show_count']) ? true : false; $hide_icon = !empty($args['hide_icon']) ? true : false; $cpt_left = !empty($args['cpt_left']) ? true : false; if(!$cpt_left){ $cpt_left = "gd-cpt-flat"; }else{ $cpt_left = ''; } $orderby = 'count'; $order = 'DESC'; if ($sort_by == 'az') { $orderby = 'name'; $order = 'ASC'; } $output = ''; if (!empty($post_types)) { foreach ($post_types as $cpt => $cpt_info) { $parent_category = ($is_category && $cat_filter && $cpt == $current_posttype) ? $current_term_id : 0; $cat_taxonomy = $cpt . 'category'; $skip_childs = false; if ($cat_filter && $cpt == $current_posttype && $is_detail && $post_ID) { $skip_childs = true; $categories = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'object_ids' => $post_ID)); } else { $categories = get_terms($cat_taxonomy, array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'parent' => $parent_category)); } if ($hide_empty) { $categories = geodir_filter_empty_terms($categories); } if ($sort_by == 'count') { $categories = geodir_sort_terms($categories, 'count'); } $categories = apply_filters('geodir_custom_sort_cpt_terms', $categories); if (!empty($categories)) { $term_icons = !$hide_icon ? geodir_get_term_icon() : array(); $row_class = ''; if ($is_listing) { $row_class = $is_category ? ' gd-cptcat-categ' : ' gd-cptcat-listing'; } $cpt_row = ''; if ($is_category && $cat_filter && $cpt == $current_posttype) { $term_info = get_term($current_term_id, $cat_taxonomy); $term_icon_url = !empty($term_icons) && isset($term_icons[$term_info->term_id]) ? $term_icons[$term_info->term_id] : ''; $term_icon_url = $term_icon_url != '' ? ' ' : ''; $count = $show_count ? ' (' . $term_info->count . ')' : ''; $cpt_row .= ''; $output .= $cpt_row; } } } $gd_use_query_vars = $old_gd_use_query_vars; return $output; }' . $term_icon_url . $term_info->name . $count . '
'; } else { $cpt_row .= '' . __($cpt_info['labels']['name'], 'geodirectory') . '
'; } foreach ($categories as $category) { $term_icon_url = !empty($term_icons) && isset($term_icons[$category->term_id]) ? $term_icons[$category->term_id] : ''; $term_icon_url = $term_icon_url != '' ? ' ' : ''; $term_link = get_term_link( $category, $category->taxonomy ); /** Filter documented in geodirectory-functions/general_functions.php **/ $term_link = apply_filters( 'geodir_category_term_link', $term_link, $category->term_id, $cpt ); $cpt_row .= ''; $cpt_row .= '
'; } $cpt_row .= '- '; $count = $show_count ? ' (' . $category->count . ')' : ''; $cpt_row .= '
'; $cpt_row .= '' .$term_icon_url . $category->name . $count . '
'; if (!$skip_childs && ($all_childs || $max_count > 0) && ($max_level == 'all' || (int)$max_level > 0)) { $cpt_row .= geodir_cpt_categories_child_cats($category->term_id, $cpt, $hide_empty, $show_count, $sort_by, $max_count, $max_level, $term_icons); } $cpt_row .= '