• 93bjones

    (@93bjones)


    We can successfully create Stores via API, however the long/lat fields do not update and it forces us to manually hit “Update” on each Store manually.

    Do you have any suggestion/fix for this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • farroyo

    (@farroyob)

    Hi there,

    Could you please be a bit more specific about the exact creation process of the stores via API? Let me know the details on how you accomplish it so I can understand.

    Regards,

    Thread Starter 93bjones

    (@93bjones)

    Hi,

    Thanks for your reply. We create new Store posts by API which is feeding from our external database of active stores. with the address, and details. The action that updates the long and lat when manually saving works fine, but this action does not trigger when creating the post by API..

    It means we currently have to open each Store created by the API and hit “Update”, then it shows up in the map and long/lat fields are completed.

    Hi!

    The only way to force a geocode request with code is calling this function and passing the address details as the param.

    Then update the wpsl_lat / wpsl_lng meta fields for the matching post ID.

    I hope that helps,
    Regards,

    Thread Starter 93bjones

    (@93bjones)

    Hi,

    Thanks for your advice. Here is the current updatepostmeta when adding via API. Could you assist with incorportating that function to this by any chance?

    function add_store(\WP_Post $post, $request, $creating) {
        $metas = $request->get_param("meta");
        if (is_array($metas)) {
            foreach ($metas as $name => $value) {
                update_post_meta($post->ID, $name, $value);
                $newpostdata['status'] = 'draft';
                wp_update_post($post->ID, $newpostdata, true);
            }
        }
    }
    add_action("rest_insert_wpsl_stores", "add_store", 20, 3);

    Hi again!

    You will have to include the /plugins/wp-store-locator/inc/wpsl-functions.php file in the functions.php to call the wpsl_get_address_latlng function, or just copy the code and place it in a custom function.

    Anohter user tried to do something similar to what you are trying and there is another thread where this is discussed.

    I hope that helps,
    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Creating Stores via API’ is closed to new replies.