Restrict listing as per post code attribute that user has provided in account setting

I want to add a community feature to my website. I want to restrict listings shown in the lisitng page to 5 km radius of the postcode that users have provided on the account setting (user attribute).

The users will only be able to see the listings posted by other users within 5 km radius of their post code.

Are there any steps/ processes I can follow to implement that or just a hint. It will be one of the essential feature of the site i am building.

Sorry for the delay.

Yes, this may be possible but requires advanced customizations. If you’re familiar with customizations, the easiest way is probably using pre_get_posts filter hook, and using the conditions applying specific restrictions to the listing queries everywhere on the front-end.

The ZIP code attribute can be added via the back-end UI or using code, when it’s saved you can make a query to the maps API to get latitude/longitude that correspond to the entered ZIP code and save it for the user. Then when you alter the listing queries, you can apply a condition to restrict the radius iphone - SQL Query for Performing Radius Search based on Latitude Longitude - Stack Overflow

Hope this helps.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.