• Resolved mbrinson

    (@mbrinson)


    I’ve inherited a project that was coded by another developer. For a single post result, the address and other contact information that is displayed does not match what is being displayed for the search results page.

    Here is the applicable line of code that is retrieving the data from the places_locator table (idw_ prefix in my particular case):

    $results = $wpdb->get_row('SELECT * FROM idw_places_locator WHERE post_id ='.$postid, ARRAY_A);

    I’ve looked in the table and I see that the data in that table does not match what I have entered into the associated location info for that post.

    See screenshot above for example of the contact info for the given page.

    And here you can see it doesn’t display the data

    According to this page: https://docs.geomywp.com/article/154-posts-locator-function-gmwupdatepostlocation “With GEO my WP, by default, it is possible to geotag a post via the location form of the “Edit Post” page of the admin’s dashboard only.

    So, I would expect that when I edit the post, then the idw_places_locator table would be updated, but when I inspect that table I can see that it does not.

    What am I missing?

    Here’s the full block of code that is responsible for displaying the contact info for the post:

    $postid = get_the_ID();
    $results = $wpdb->get_row('SELECT * FROM idw_places_locator WHERE post_id ='.$postid, ARRAY_A);
    $dentist_email = $results['email'];?>
    <div id="dentist-info">
    <div class="one-half first">
    <span class="address-label">Address:</span>
    <p><?php echo $results['street'];?> <?php echo $results['apt'];?> <br />
    <?php echo $results['city'];?> <?php echo $results['state'];?> <?php echo $results['zipcode'];?></p>
    <?php /*if ($dentist_email !=""){?><a class="fancybox-inline" href="#fancyboxID-SM"><button>click to contact</button></a><?php }*/?>
    </div>
    <div class="one-half">
    <span class="address-label">Phone:</span>
    <p><?php echo $results['phone'];?></p>
    <span class="address-label">Website:</span>
    <p><?php
    $website = $results['website'];
    echo '<a href="'.$website.'" rel="nofollow" target="_blank" id="website-link">'.$results['website'].'</a>';?>
    </p>
    </div>
    </div>

    I can verify that this is working for other posts. The data for this post just isn’t being updated to the idw_places_locator table when that post is saved as I would expect. In other words, it is correct for this page (from a coding standpoint) to be displaying nothing, because those fields are indeed empty for this post in the idw_places_locator, even though you can see that there is data in the phone and website fields in the location section of that post in the back end.

    • This topic was modified 4 weeks ago by mbrinson.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter mbrinson

    (@mbrinson)

    Nevermind, it looks like this was a custom table that was added by the previous developer, probably because they didn’t know how to query correctly from the existing gmw_ tables.

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Hello @mbrinson,

    The database table ‘places_locator’ was replaced with the tables “gmw_locations” and “gmw_location_meta” in GEO my WP v3.0 ( a while ago ). And based on the screenshot that you provided, it appears that on the site you are working on you are using GEO my WP v4.0.X. So you might want to look for those tables in the database and see if they exist and if they get updated when you update the location of a post.

    Now, GEO my WP has a couple of functions that you can ( and perhaps should ) use in order to retrieve the location of a post rather than using a direct SQL call.

    1. gmw_get_post_location( post_id ); – to retrieve the location of a post.
    2. gmw_get_post_location_meta( post_id, meta_keys ) – to retrieve the location meta ( phone, website, email… ) of a post.

    So in your custom script you can use something like the below:

    // Post ID
    $postid = get_the_ID();

    // Get the location data.
    $location = gmw_get_post_location( $postid );

    // Array of meta field to retrieve.
    $meta_fields = array( 'email', 'phone', 'website' );

    // Get the location meta fields.
    $location_meta = gmw_get_post_location_meta( $postid, $meta_fields );

    Note that the $location is an object. So to populate a value you can do some like:

    // Check if street exists and if so display it while also sanitizing it.
    echo ! empty( $location->street ) ? esc_attr( $location->street ) :'';

    // Check if postcode exists and if so display it while also sanitizing it.
    echo ! empty( $location->postcode ) ? esc_attr( $location->postcode ) :'';

    The $location_meta is an array and you can use the below to output it:

    // Check if phone exists and if so display it while also sanitizing it.
    echo ! empty( $location_meta['phone'] ) ? esc_attr( $location_meta['phone'] ) :'';

    I hope this helps.

    Let me know if you have any questions or issues.

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Ah, looks like we replied at the same time.

    No, the places_locator is the original table created by GEO my WP and was replaced at some point.

    Anyway, I hope my reply above helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.