Programatically inserting posts doesn’t generate lat/lng data
-
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 acurrent_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 tosave_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.
- The topic ‘Programatically inserting posts doesn’t generate lat/lng data’ is closed to new replies.