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 5941391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:06:11+00:00 2026-05-22T16:06:11+00:00

Currently I’m running this SQL query to retrieve custom posts for a store locator.

  • 0

Currently I’m running this SQL query to retrieve custom posts for a store locator. Everything is fine except I would like for it to return items even if the “telephone” field is empty. As of now it will only pull in the ones that have that field filled in.

This is how my query looks when run:

my query

Anyone have a clue? (Also is there a more efficient way to run this?)

SELECT   wp_posts.post_title as name, 

        address.meta_value as address,
        latitude.meta_value as lat,
        longitude.meta_value as lng,
        telephone.meta_value as phone,


        ( 3959 * acos(
        cos( radians( '%s' ) ) *
        cos( radians( CONVERT( latitude.meta_value, DECIMAL( 10, 6 ) ) ) ) *
        cos( radians( CONVERT( longitude.meta_value, DECIMAL( 10, 6 ) ) ) - radians( '%s' ) ) +
        sin( radians( '%s' ) ) * sin( radians( CONVERT( latitude.meta_value, DECIMAL( 10, 6 ) ) ) )
         ) ) AS distance

        FROM wp_postmeta as address, wp_postmeta as latitude, wp_postmeta as longitude, wp_postmeta as telephone,
         wp_posts

WHERE   
    (wp_posts.ID = address.post_id
        AND address.meta_key = '_dealer_address' )  

AND     (wp_posts.ID = latitude.post_id
        AND latitude.meta_key = '_dealer_latitude' )

AND     (wp_posts.ID = longitude.post_id
        AND longitude.meta_key = '_dealer_longitude' )      

AND     (wp_posts.ID = telephone.post_id
        AND telephone.meta_key = '_dealer_telephone' )  
  • 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-22T16:06:12+00:00Added an answer on May 22, 2026 at 4:06 pm

    Posting the answer as per Marc B’s suggestion from his comment.

         SELECT  wp_posts.post_title as name, 
    address.meta_value as address,
     latitude.meta_value as lat,
     longitude.meta_value as lng,
     telephone.meta_value as telephone,
    
       ( 3959 * acos(
        cos( radians( '%s' ) ) *
        cos( radians( CONVERT( latitude.meta_value, DECIMAL( 10, 6 ) ) ) ) *
        cos( radians( CONVERT( longitude.meta_value, DECIMAL( 10, 6 ) ) ) - radians( '%s' ) ) +
        sin( radians( '%s' ) ) * sin( radians( CONVERT( latitude.meta_value, DECIMAL( 10, 6 ) ) ) )
         ) ) AS distance
    
    FROM wp_posts
    LEFT JOIN wp_postmeta AS address ON(
    wp_posts.ID = address.post_id
    AND address.meta_key = '_dealer_address'
    )
    LEFT JOIN wp_postmeta AS latitude ON(
    wp_posts.ID = latitude.post_id
    AND latitude.meta_key = '_dealer_latitude'
    )
    LEFT JOIN wp_postmeta AS longitude ON(
    wp_posts.ID = longitude.post_id
    AND longitude.meta_key = '_dealer_longitude'
    )
    LEFT JOIN wp_postmeta AS telephone ON(
    wp_posts.ID = telephone.post_id
    AND telephone.meta_key = '_dealer_telephone'
    )
    WHERE wp_posts.post_type = 'dealers' HAVING distance < '%s' ORDER BY distance LIMIT 0 ,         20
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm storing the settings for my custom addins in the registry but this
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Currently, if I want to output a SQL script for a table in my
Currently, I am developing a product that does fairly intensive calculations using MS SQL
Currently my AJAX is working like this: index.php <a href='one.php' class='ajax'>One</a> <div id=workspace>workspace</div> one.php
Currently my web.config has this: <appSettings> <add key=UserName /> <add key=DBServer /> <add key=DBUserName
Currently stuck in C# 2, it would still be nice to use the parallel
Currently I am doing one query, with 3 sub queries, all queries are on
Currently im having this for displaying my statusmessages: <?php while($showSe = mysql_fetch_array($stringUSS)) { ?>
I am currently running into a problem where an element is coming back from

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.