title: wordpress get posts within radius defiend by user
body: <p><strong>Details</strong> </p>
  
  <p>Ok. So i have a custom field on my posts called Location. This location is geocoded into LAT LNG values. </p>
  
  <p>I also have a custom field for users that does the exact same thing. The user can also define a radius in miles or kilometers. only posts within this radius are to show up.  </p>
  
  <p>I can calculate the distance between the posts lat lng and the users lag lng inside my query_posts loop by getting the posts meta data(lat long) and compare it to the users. </p>
  
  <p>If i do this inside the loop and wrap an if statement that basically says if less then radius display post i get only posts with in the radius.</p>
  
  <p><strong>Problem</strong><br>
  Lets say i add a posts_per_page of 5 and the first 5 posts to loop are not within the defined radius it will display 0 posts. If the first 3 are not within the radius i will get 2 posts. And so on. </p>
  
  <p><strong>Need solution</strong></p>
  
  <p>1) Obviously the best way to go about this would be inside my query. I'm ok with using wp_query vs query_posts however i'm not 100% sure how i can run my PHP function to calculate the distance between the users and posts lat + lng's right inside the query.</p>
  
  <p>2) Is there a way to increase query_posts post_per_page by 1 if my if statement is not met inside an else?</p>
  
  <p><strong>Conclusion</strong>  </p>
  
  <p>Thanks in advance for anyone that has some insight on this. If i did not give enough info just let me know and i will try to explain more clearly. I could post code but im not looking for code in return. Just a point in the right direction. </p>
  
  <p>Cheers!</p>