title: Sort WordPress posts by proximity to a latitude and longitude
body: <p>I have a a bunch of posts in WordPress. These posts are in a category called "Restaurants". Each post has a custom meta key/value stored with it like so:</p>
  
  <pre><code>$post_geocode = get_post_meta($post-&gt;ID, 'geocode', true);
  // $post_geocode = '34.0510613,-118.244705'
  </code></pre>
  
  <p>You have to be logged into WordPress to use my site, so each user has a Geocode stored for them, like so:</p>
  
  <pre><code>$user_geocode = get_user_meta( $user-&gt;ID, 'geocode', true );
  // $user_geocode = '34.043925,-118.2424291'
  </code></pre>
  
  <p>So I want to be able to get posts and rank them in order to their proximity to the users location.</p>
  
  <p>Ideally it would use the WP Query class. But <strong>I am happy to change the way the geocodes are stored if needed.</strong> </p>
  
  <p>The best answer would look something like this:</p>
  
  <pre><code>// This is how I manage the type of restaurant you'll see (eg: Mexican, Italian etc)
  $cat_query = array(
      'taxonomy'  =&gt; 'category',
      'field'     =&gt; 'slug',
      'terms'     =&gt; $restaurant_category, 
      'operator'  =&gt; 'IN'
  );
  
  // Go and get the posts
  $args = array(
      'post_type'         =&gt; 'post',
      'post_status'       =&gt; 'publish',
      'posts_per_page'    =&gt; -20,
      'geocode'               =&gt; $user_geocode, // WOuld love this to work!!!
      'orderby'           =&gt; 'geocode', // Would love this to work!!!
      'fields'            =&gt; 'ids',
      'tax_query'         =&gt; array(
          'relation'      =&gt; 'AND',
          $cat_query,
      )
  );          
  
  $posts = get_posts($args);
  </code></pre>