Skip Navigation

[Resolved] Get CPT filtered by distance from location in PHP

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 2 months, 2 weeks ago.

Assigned support staff: Waqar.


I'm trying to get a list of posts with a location custom field that is within a certain distance from a specific point.
This is easy enough to do with a view, but I would like to have more control over what I'm doing and do this directly in PHP. Since Toolset is doing this somehow for views, I'm hoping there is some way for me to hook into it lower down and re-use it in my PHP code. Any ideas?




Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)


Thank you for contacting us and I'd be happy to assist.

I've done some testing and research and couldn't find any public function or API for this, that can be used without the view's query.

For this reason, it would be best to use a view for this distance-based filtering and then use the view's output/result in the PHP code, as needed.
( ref: )