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

  • Home
  • SEARCH
  • 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 4340960
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:25:12+00:00 2026-05-21T11:25:12+00:00

Inside phpMyAdmin, I am working with custom meta fields in WordPress. Say I have

  • 0

Inside phpMyAdmin, I am working with custom meta fields in WordPress.

Say I have custom meta for 3 fields- Address, Latitude, Longitude and wish to run an SQL query to display only these 3 columns with their values as rows below.

I can only figure out how to get one of the columns to show, and it’s data by running this:

SELECT DISTINCT wp_postmeta.meta_value AS address
FROM wp_postmeta, wp_posts
WHERE post_type = ‘dealers’
AND wp_postmeta.meta_key = ‘_dealer_address’

Could someone point me in a direction of how to run the query to include all 3 columns?

What I’m trying to do is mimic the setup of the table in this: http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html#outputxml

Because I have a custom post type (dealers) using your custom metabox for latitude and longitude.

Your SQL query tested just fine in phpMyAdmin and looked identical to my other manually-created test dealer table, but when I tried to replace the google maps example query in the PHP- it was a no-go.

Is it too complicated of a query you think?

This is the test query that works without using the wordpress custom post:

$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
  • 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-05-21T11:25:13+00:00Added an answer on May 21, 2026 at 11:25 am

    Definitely stay away from distinct. 99% of the time, it’s a sign that something’s wrong (with the schema or your understanding of the schema).

    I think that Cheluis’ suggestion might not associate the lat/long with the address.

    I don’t have a wordpress installation to play with. I really hope that there’s a primary key (say, post_id). You don’t use it to join the two tables together in your original example, which is probably why you’re using the distinct.

    If this id exists, you can join back to the wp_postmeta table several times, e.g.

    SELECT meta1.meta_value AS address, meta2.meta_value as latitude, meta3.meta_value as longitude
    FROM wp_posts posts, wp_postmeta meta1, wp_postmeta meta2, wp_postmeta meta3
    WHERE posts.post_type = ‘dealers’
    AND posts.post_id = meta1.post_id
    AND meta1.meta_key = ‘_dealer_address’
    AND posts.post_id = meta2.post_id
    AND meta2.meta_key = ‘_dealer_latitude’
    AND posts.post_id = meta3.post_id
    AND meta3.meta_key = ‘_dealer_longitude’
    

    This assumes that each dealer will have all three attributes. If not, you’ll need to switch to an outer join, which will make the query even more ugly.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside my page, I have the following: <aspe:UpdatePanel runat=server ID=updatePanel> <ContentTemplate> <local:KeywordSelector runat=server ID=ksKeywords
Working inside the context of an ASP.NET application I am creating a page that
I have table inside a div tab. The table has 40 rows in it
When working with CSS inside of XML such as <span class=IwuvAS3></span> when parsed in
I have a button inside an updatepanel. I have a PopupControlExtender linked to the
I'm working on an ASP.NET MVC site which will have a database. While I'm
i have a backup from a data base (SQL Server), i never worked with
Inside ActionController class (rails/actionpack/lib/action_controller.lib) I found several weird code. I don't really have a
Inside a process I have something like this: CASE res IS WHEN 00 =>
Inside a batch file on Windows I would like some variable to have the

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.