• I’ve got a WP-CLI command set up that syncs store locator locations from a third party. It boils down to running:

    wp_update_post($args);

    This inserts and updates locations just fine. However, your save_post hook, which is responsible for a few things, including geocoding the address, short-circuits if it doesn’t see the anticipated fields in the $_POST array. Obviously, when inserting posts programmatically, there isn’t anything in the $_POST array. It also short-circuits on a current_user_can call, and once again, during WP-CLI operations, there is no user.

    It’d be great if this were compatible with all situations in which the save_post action fires. Pretty much everything here either returns false or is depending on data that may not be present:

    if ( empty( $_POST['wpsl_meta_nonce'] ) || !wp_verify_nonce( $_POST['wpsl_meta_nonce'], 'save_store_meta' ) )
        return;
    
    if ( !isset( $_POST['post_type'] ) || 'wpsl_stores' !== $_POST['post_type'] )
        return;
    
    // ...
    
    if ( !current_user_can( 'edit_post', $post_id ) )
        return;
    
    $this->store_data = $_POST['wpsl'];

    The post_type check could be resolved by changing the hook you subscribe to to save_post_wpsl_stores (see here).

    The capability check can probably be safely omitted.

    And then $this->store_data would have to depend on post meta fetched from the database rather than the $_POST information.

    The rest I would have to leave you to decide.

    Let me know if I’m totally misunderstanding why geocoding isn’t happening on our import, or if you have a clever way of getting around this in the meantime.

    • This topic was modified 4 years, 1 month ago by eclev91.
    • This topic was modified 4 years, 1 month ago by eclev91.
    • This topic was modified 4 years, 1 month ago by eclev91.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter eclev91

    (@eclev91)

    (and if you have this thing in git somewhere, I’d be happy to work on a pull request to resolve some of these items)

    Plugin Author Tijmen Smit

    (@tijmensmit)

    Sorry for the late response, and thanks for pointing this out. I wasn’t aware of this issue. I have to look into the best way to make this work with WP-CLI.

    I do plan to implement support for the REST API and allow insert / updates in combination with application passwords in the 3.0 update.

    I never really used the WP CLI myself, but I assume you can make calls to the REST API from it?

    As a workaround for now you could call this function with the used address and then update the corresponding meta data yourself.

    • This reply was modified 4 years, 1 month ago by Tijmen Smit.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Programatically inserting posts doesn’t generate lat/lng data’ is closed to new replies.