Function Reference: geodir_location_list
Summary
Get locations using given arguments.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
Package
GeoDirectory_Location_Manager
Parameters
- $args
- (array) (required) Query args.
- Default: None
Return Values
- (array)
- Location array.
Change Log
Since: 1.0.0
Source File
geodir_location_list() is located in geodir_location_manager/geodir_location_functions.php [Line: 2923]
Source Code
function geodir_location_list( $args = array() ) {
global $wpdb;
$where = '';
if ( !empty( $args['search'] ) && $args['search'] != '' ) {
$where .= "AND ( city LIKE '" . wp_slash( $args['search'] ) . "%' OR region LIKE '" . wp_slash( $args['search'] ) . "%' ) ";
}
if ( !empty( $args['country'] ) && $args['country'] != '' ) {
$where .= "AND ( country LIKE '" . wp_slash( $args['country'] ) . "' OR country_slug LIKE '" . wp_slash( $args['country'] ) . "' ) ";
}
$sql = "SELECT COUNT(location_id) FROM " . POST_LOCATION_TABLE . " WHERE 1=1 " . $where;
$total_items = $wpdb->get_var( $sql );
if ( !empty( $args['count'] ) ) {
return $total_items;
}
$total_pages = ( $total_items > 0 && isset( $args['per_page'] ) && $args['per_page'] > 0 ) ? ceil( $total_items / $args['per_page'] ) : 0;
$args['total_pages'] = $total_pages;
$pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
if ( isset( $args['total_pages'] ) && $pagenum > $args['total_pages'] ) {
$pagenum = $args['total_pages'];
}
$pagenum = max( 1, $pagenum );
$args['total_items'] = $total_items;
$args['pagenum'] = $pagenum;
$limits = '';
if ( isset( $args['per_page'] ) && $args['per_page'] > 0 ) {
$offset = ( $pagenum - 1 ) * $args['per_page'];
if ( $offset > 0 ) {
$limits = 'LIMIT ' . $offset . ',' . $args['per_page'];
} else {
$limits = 'LIMIT ' . $args['per_page'];
}
}
$sql = "SELECT * FROM " . POST_LOCATION_TABLE . " WHERE 1=1 " . $where . " ORDER BY city, region, country ASC " . $limits;
$items = $wpdb->get_results( $sql );
$result = array();
$result['items'] = $items;
$result['total_items'] = $total_items;
$result['total_pages'] = $total_pages;
$result['pagenum'] = $pagenum;
$result['pagination'] = geodir_location_admin_pagination( $args );
$result['pagination_top'] = geodir_location_admin_pagination( $args, 'top' );
$result['filter_box'] = geodir_location_admin_search_box( __( 'Filter', GEODIRLOCATION_TEXTDOMAIN ), 'location' );
return $result;
}