在搜索结果按字母顺序排序的那一刻。 我需要它们按最接近搜索位置排序。 我正在使用WP职业经理,搜索由谷歌地图api提供
function get_job_listings($ args = array()){ global $ wpdb,$ job_manager_keyword;
$args = wp_parse_args( $args, array(
'search_location' => '',
'search_keywords' => '',
'search_categories' => array(),
'job_types' => array(),
'post_status' => array(),
'offset' => 0,
'posts_per_page' => 20,
'orderby' => 'date',
'order' => 'DESC',
'featured' => null,
'filled' => null,
'fields' => 'all'
) );
if ( $args['posts_per_page'] < 0 ) {
$query_args['no_found_rows'] = true;
}
if ( ! empty( $args['search_location'] ) ) {
$location_meta_keys = array( 'geolocation_formatted_address', '_job_location', 'geolocation_state_long' );
$location_search = array( 'relation' => 'OR' );
foreach ( $location_meta_keys as $meta_key ) {
$location_search[] = array(
'key' => $meta_key,
'value' => $args['search_location'],
'compare' => 'like'
);
}
$query_args['meta_query'][] = $location_search;
}
if ( ! is_null( $args['featured'] ) ) {
$query_args['meta_query'][] = array(
'key' => '_featured',
'value' => '1',
'compare' => $args['featured'] ? '=' : '!='
);
}
if ( ! is_null( $args['filled'] ) || 1 === absint( get_option( 'job_manager_hide_filled_positions' ) ) ) {
$query_args['meta_query'][] = array(
'key' => '_filled',
'value' => '1',
'compare' => $args['filled'] ? '=' : '!='
);
}
if ( ! empty( $args['job_types'] ) ) {
$query_args['tax_query'][] = array(
'taxonomy' => 'job_listing_type',
'field' => 'slug',
'terms' => $args['job_types']
);
}
if ( ! empty( $args['search_categories'] ) ) {
$field = is_numeric( $args['search_categories'][0] ) ? 'term_id' : 'slug';
$operator = 'all' === get_option( 'job_manager_category_filter_type', 'all' ) && sizeof( $args['search_categories'] ) > 1 ? 'AND' : 'IN';
$query_args['tax_query'][] = array(
'taxonomy' => 'job_listing_category',
'field' => $field,
'terms' => array_values( $args['search_categories'] ),
'include_children' => $operator !== 'AND' ,
'operator' => $operator
);
}
如果您需要更多代码,请告诉我们。