• I created a locator some time ago but it wasn’t very wordpress friendly, now I’m redoing the code and I’m using custom posts and custom data fields.
    Since I’m not using my own tables anymore how do i do the the following query to get all the stores within a range of an address using the wordpress tables?

    SELECT distinct m.id,
                    m.address,
                    m.name,
                    m.lat,
                    m.lng,
                    ( '$distance' * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance,
                    m.email,
                    m.phone,
                    m.fax,
                    m.url as website,
                    m.id_entity_type,
                    m.isactive,
                    m.sellsOnline,
                    m.hasContests,
                    m.wheelchairAccess,
                    l.id_store,
                    l.title,
                    l.url,
                    l.thumb,
                    so.vote_average,
                    m.created_by
                    FROM ".$wpdb->prefix."stores m
                    left join ".$wpdb->prefix."logo l on l.id_store = m.id
                    left join ".$wpdb->prefix."entity_rating so on so.id_entity = m.id
                    left join ".$wpdb->prefix."store_game_subdomain gc on gc.id_store = m.id
                    where m.isactive=1 and ('$name' = '' or m.name like '%%%s%%') and
                    ('$sellsOnline' = 0 or m.sellsOnline = '$sellsOnline') and
                    ('$contests' = 0 or m.hasContests = '$contests') and
                    ('$wheelchairAccess' = 0 or m.wheelchairAccess = '$wheelchairAccess') and
                    ('$sellsFoodDrinks' = 0 or m.sellsFoodDrinks = '$sellsFoodDrinks') and
                    ('$subdomainIds' = '' or gc.id_game_subdomain in ('$subdomainIds'))
                    HAVING '$radius' = '' or distance < '%s'
                    ORDER BY distance

    Is it possible?
    Thanks in advance!

The topic ‘Get posts within an address range’ is closed to new replies.