Function Reference: geodir_insert_term_count_by_loc
Summary
Insert term count for a location.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
Package
GeoDirectory_Location_Manager
Parameters
- ($location_name) (required)
- Default: None
- $location_type
- (string) (required) Location type. Possible values ‘gd_city’,’gd_region’,’gd_country’.
- Default: None
- $count_type
- (string) (required) Count type. Possible values are ‘review_count’, ‘term_count’.
- Default: None
- $row_id
- (null) (required)
- 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
Return Values
- (array)
Change Log
Since: 1.0.0
Source File
geodir_insert_term_count_by_loc() is located in geodir_location_manager/geodir_count_functions.php [Line: 128]
Source Code
function geodir_insert_term_count_by_loc($location_name, $location_type, $count_type, $row_id=null,$loc) { global $wpdb; $post_types = geodir_get_posttypes(); $term_array = array(); foreach($post_types as $post_type) { $taxonomy = geodir_get_taxonomies($post_type); $taxonomy = $taxonomy[0]; $args = array( 'hide_empty' => false, 'gd_no_loop' => true ); $terms = get_terms($taxonomy, $args); foreach ($terms as $term) { $count = geodir_filter_listings_where_set_loc($term->term_id, $taxonomy, $post_type, $location_type, $loc, $count_type); $term_array[$term->term_id] = $count; } } $data = serialize($term_array); if ( $row_id ) { $wpdb->query( $wpdb->prepare( "UPDATE " . GEODIR_TERM_META . " set " . $count_type . " = %s WHERE id=" . $row_id . "", array( $data ) ) ); } else { $wpdb->query( $wpdb->prepare( "INSERT into " . GEODIR_TERM_META . " set location_type = %s, location_name = %s, " . $count_type . " = %s", array( $location_type, $location_name, $data ) ) ); } return $term_array; }