WordPress にはたくさんの投稿があります。これらの投稿は「レストラン」というカテゴリにあります。各投稿には、次のように保存されたカスタム メタ キー/値があります。
$post_geocode = get_post_meta($post->ID, 'geocode', true);
// $post_geocode = '34.0510613,-118.244705'
私のサイトを使用するには WordPress にログインする必要があるため、各ユーザーには次のようにジオコードが保存されています。
$user_geocode = get_user_meta( $user->ID, 'geocode', true );
// $user_geocode = '34.043925,-118.2424291'
そのため、投稿を取得して、ユーザーの場所に近い順にランク付けできるようにしたいと考えています。
WP Query クラスを使用するのが理想的です。しかし、必要に応じて、ジオコードの保存方法を喜んで変更します。
最良の答えは次のようになります。
// This is how I manage the type of restaurant you'll see (eg: Mexican, Italian etc)
$cat_query = array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $restaurant_category,
'operator' => 'IN'
);
// Go and get the posts
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -20,
'geocode' => $user_geocode, // WOuld love this to work!!!
'orderby' => 'geocode', // Would love this to work!!!
'fields' => 'ids',
'tax_query' => array(
'relation' => 'AND',
$cat_query,
)
);
$posts = get_posts($args);