Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:23:19+00:00 2026-06-11T14:23:19+00:00

Details Ok. So i have a custom field on my posts called Location. This

  • 0

Details

Ok. So i have a custom field on my posts called Location. This location is geocoded into LAT LNG values.

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.

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.

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.

Problem
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.

Need solution

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.

2) Is there a way to increase query_posts post_per_page by 1 if my if statement is not met inside an else?

Conclusion

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.

Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:23:20+00:00Added an answer on June 11, 2026 at 2:23 pm

    Here is my final query. Does exactly what i need it to do. I have created a custom table in my database to store lat and lng info from posts VS adding them to the post meta table so i could join the 2 and get the distance from the post to the user. Any question let me know 🙂

    $querystr = '
                SELECT *,
                (((acos(sin(('.$userLat.'*pi()/180)) * sin((lat*pi()/180))+cos(('.$userLat.'*pi()/180)) * cos((lat*pi()/180)) * cos((('.$userLng.'- lng)*pi()/180))))*180/pi())*60*1.1515) as distance
                FROM wp_posts, tbl_post_lat_lng
                WHERE wp_posts.ID = tbl_post_lat_lng.post_id
                AND wp_posts.post_status = "publish"
                AND wp_posts.post_type = "post"
                AND distance <= '.$userRadius.'
                ORDER BY wp_posts.post_date DESC
                LIMIT 5
             ';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom object called Technology__c and join object called AccountTechnologies which is
I'm defining my custom model for pas.plugin.sqlalchemy. Existing table of login details have binary
I have created custom post types that also have custom meta_boxes I've created. Currently,
I'm trying to implement the Media Player custom field control described in this MSDN
I've created a custom object, I have it appearing automatically on the Account details
I am using advanced custom fields in Wordpress. Without going into the details of
So I have this custom ModelForm that I created that takes in a variable
I have one custom config file. <Students> <student> <Detail Name=abc Class=1st Year> <add key=Main
In a Ruby on Rails app, we have some details which are stored as
I'm using C# DLL in a VC++ application. I have some details in VC++

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.