Function Reference: geodir_get_cat_postcount
Summary
Get post count for the given category / term.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $plugin_prefix
- (string) (required) Geodirectory plugin table prefix.
- Default: None
Package
GeoDirectory
Parameters
- $term
- (object|array) (required) category / term object that need to be processed.
- Default: None
Return Values
- (bool|int|null|string)
- Post count.
Change Log
Since: 1.0.0
Filters
‘geodir_cat_post_count_join’ [Line: 2604]
‘geodir_cat_post_count_where’ [Line: 2614]
Source File
geodir_get_cat_postcount() is located in geodirectory-functions/post_functions.php [Line: 2580]
Source Code
function geodir_get_cat_postcount($term = array()) { if (!empty($term)) { global $wpdb, $plugin_prefix; $where = ''; $join = ''; if (get_query_var('gd_country') != '' || get_query_var('gd_region') != '' || get_query_var('gd_city') != '') { $taxonomy_obj = get_taxonomy($term->taxonomy); $post_type = $taxonomy_obj->object_type[0]; $table = $plugin_prefix . $post_type . '_detail'; /** * Filter to modify the 'join' query * * @since 1.0.0 * @package GeoDirectory * @param object|array $term category / term object that need to be processed. * @param string $join The join query. */ $join = apply_filters('geodir_cat_post_count_join', $join, $term); /** * Filter to modify the 'where' query * * @since 1.0.0 * @package GeoDirectory * @param object|array $term category / term object that need to be processed. * @param string $where The where query. */ $where = apply_filters('geodir_cat_post_count_where', $where, $term); $count_query = "SELECT count(post_id) FROM " . $table . " as pd " . $join . " WHERE pd.post_status='publish' AND FIND_IN_SET('" . $term->term_id . "'," . $term->taxonomy . ") " . $where; $cat_post_count = $wpdb->get_var($count_query); if (empty($cat_post_count) || is_wp_error($cat_post_count)) $cat_post_count = 0; return $cat_post_count; } else return $term->count; } return false; }