Custom query to get listings by distance

This topic contains 5 replies, has 4 voices, and was last updated by  Kiran 5 years, 5 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #496377

    Dave
    Full Member
    Post count: 205

    How do I run a query places near to the currently displayed listing?

    I cannot use a conventional wp_query as that doesn’t factor in the geolocation data.

    I’m assuming there is a function in GD to query listings in this manner, what is it and where can I find the syntax for using it?

    #496421

    Kor
    Moderator
    Post count: 16516

    Hi David,

    Thanks for your post. You can use the “Location Filter” as explained here https://wpgeodirectory.com/docs-v2/design/gd-listings/#options to “show all the listings IN the same city as the listing being viewed”

    #496614

    Dave
    Full Member
    Post count: 205

    No that’s not what I need.

    I need the actual query syntax to create a custom query for places near a given postcode. So, in other words, I need to create our own set of results like the GD Search does.

    I have tried using wp_query but I cannot see how to include geolocation data into the results.

    We need them sorted by distance with the nearest first.

    #496649

    Alex Rollin
    Moderator
    Post count: 27815

    Hi David,

    We don’t provide support in the forum for programmatic customization of the plugin. In cases where a filter or hook might serve we do our best, though.

    I have asked a developer to take a look at your topics to see where they can advise you. However, the general recommendation is to use the API because that is the recommended way to make queries or to produce custom functionality.

    #496665

    Dave
    Full Member
    Post count: 205

    Understood, how would we perform a query of this kind using the API?

    #496827

    Kiran
    Moderator
    Post count: 7069

    Hello David,

    This has been implemented and it will be in next release of GeoDirectory & Location Manager.

    Nearest listings can be retrieved by using latitude & longitude.

    API Query will be https://YOURSITE.COM/wp-json/geodir/v2/markers/?post_type=gd_place&lat=22.25865&lon=71.192380&dist=100
    – lat = Latitude
    – lon = Longitude
    – dist = Distance Radius(if not passed default distance will be taken from setting)

    Kiran

Viewing 6 posts - 1 through 6 (of 6 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount