Function Reference: count_listings_by_country
Summary
Get location count for a country.
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
- $country
- (string) (required) Country name.
- Default: None
- $country_slug
- (string) (required) Country slug.
- Default: None
- $with_translated
- (bool) (required) Return with translation? Default: true.
- Default: None
Return Values
- (int)
- Listing count.
Change Log
Since: 1.0.0
Source File
count_listings_by_country() is located in geodir_location_manager/geodir_location_functions.php [Line: 2530]
Source Code
function count_listings_by_country( $country, $country_slug='', $with_translated=false ) {
global $wpdb, $plugin_prefix;
$geodir_posttypes = geodir_get_posttypes();
$total = 0;
if ( $country == '' ) {
return $total;
}
foreach( $geodir_posttypes as $geodir_posttype ) {
$table = $plugin_prefix . $geodir_posttype . '_detail';
if( $with_translated ) {
$country_translated = __( $country, GEODIRECTORY_TEXTDOMAIN);
$sql = "SELECT COUNT(*) FROM " . $table . " WHERE post_country LIKE '".$country."' OR post_country LIKE '".$country_translated."' OR post_locations LIKE '%,[".$country_slug."]'";
} else {
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM " . $table . " WHERE post_country LIKE %s", array( $country ) );
}
$count = (int)$wpdb->get_var( $sql );
$total += $count;
}
return $total;
}