Function Reference: geodir_filter_listings_where_set_loc

Summary

Get review count or term count.

Global Values

$wpdb
(object) (required) WordPress Database object.

Default: None
$plugin_prefix
(string) (required) Geodirectory plugin table prefix.

Default: None

Package

GeoDirectory_Location_Manager

Parameters

$term_id
(int|string) (required) The term ID.

Default: None
$taxonomy
(string) (required) Taxonomy slug.

Default: None
$post_type
(string) (required) The post type.

Default: None
$location_type
(string) (required) Location type. Possible values ‘gd_city’,’gd_region’,’gd_country’.

Default: None
$loc
(array) (required) {
Attributes of the location array. @type string $gd_country The country slug. @type string $gd_region The region slug. @type string $gd_city The city slug. }.

Default: None
$count_type
(string) (required) Count type. Possible values are ‘review_count’, ‘term_count’.

Default: None

Return Values

(int|null|string)

    Change Log

    Since: 1.0.0

    Filters

    ‘geodir_location_count_reviews_by_term_sql’ [Line: 87]

    Source File

    geodir_filter_listings_where_set_loc() is located in geodir_location_manager/geodir_count_functions.php [Line: 33]

    Source Code

    function geodir_filter_listings_where_set_loc( $term_id, $taxonomy, $post_type, $location_type,$loc, $count_type ) {
    	global $wpdb, $plugin_prefix;
    
    	$table = $plugin_prefix . $post_type . '_detail';
    
        if(!$loc){
    
            $loc = geodir_get_current_location_terms();
        }
    
    	$country ='';
    	$region ='';
    	$city = '';
    	if (isset($loc['gd_city']) && $loc['gd_city'] != '') {
    		$city = $loc['gd_city'];
    	}
    	if (isset($loc['gd_region']) && $loc['gd_region'] != '') {
    		$region = $loc['gd_region'];
    	}
    	if (isset($loc['gd_country']) && $loc['gd_country'] != '') {
    		$country = $loc['gd_country'];
    	}
    
    	$where = '';
    	if ( $country!= '') {
    		$where .= " AND post_locations LIKE '%,[".$country."]' ";
    	}
    
    	if ( $region != '' && $location_type!='gd_country' ) {
    		$where .= " AND post_locations LIKE '%,[".$region."],%' ";
    	}
    
    	if ( $city != '' && $location_type!='gd_country' && $location_type!='gd_region' ) {
    		$where .= " AND post_locations LIKE '[".$city."],%' ";
    	}
    
    
    	if ($count_type == 'review_count') {
    		$sql = "SELECT COALESCE(SUM(rating_count),0) FROM  $table WHERE post_status = 'publish' $where AND FIND_IN_SET(" . $term_id . ", " . $taxonomy . ")";
    	}else {
    		$sql = "SELECT COUNT(post_id) FROM  $table WHERE post_status = 'publish' $where AND FIND_IN_SET(" . $term_id . ", " . $taxonomy . ")";
    	}
    	/**
    	 * Filter terms count sql query.
    	 *
    	 * @since 1.3.8
    	 * @param string $sql Database sql query..
    	 * @param int $term_id The term ID.
    	 * @param int $taxonomy The taxonomy Id.
    	 * @param string $post_type The post type.
    	 * @param string $location_type Location type .
    	 * @param string $loc Current location terms.
    	 * @param string $count_type The term count type.
    	 */
    	$sql = apply_filters('geodir_location_count_reviews_by_term_sql', $sql, $term_id, $taxonomy, $post_type, $location_type, $loc, $count_type);
    
    	///echo $sql;exit;
    	$count = $wpdb->get_var($sql);
    
    	return $count;
        //todo: Following code is unreachable. remove it if not necessary.
        $count = 0;
    	if ($count_type == 'review_count') {
    		foreach($rows as $post) {
    			$count = $count + $post->comment_count;
    		}
    	} elseif ($count_type == 'term_count') {
    		$count = count($rows);
    	}
    
    	return $count;
    }