Title: Insert location data with functions
Last modified: August 21, 2016

---

# Insert location data with functions

 *  Resolved [txemaleon](https://wordpress.org/support/users/txemaleon/)
 * (@txemaleon)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-location-data-with-functions/)
 * Hi.
 * I’m writing a plugin and I want it to insert posts with type location. I know
   how to do this and how to insert the custom fields with wp_insert_post() and 
   add_metadata(), but I want it to also insert the address, city, etc.
 * Is there any function provided with Events Manager or how could I achieve this?
 * [http://wordpress.org/plugins/events-manager/](http://wordpress.org/plugins/events-manager/)

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

 *  [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * (@caimin_nwl)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-location-data-with-functions/#post-4486918)
 * Hi,
 * Do you want to put together something that works with Events Manager locations,
   or something that replicates the locations feature but is separate?
 *  Thread Starter [txemaleon](https://wordpress.org/support/users/txemaleon/)
 * (@txemaleon)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-location-data-with-functions/#post-4486937)
 * Hi, I wanted to put locations in the database using the Events Manager functions,
   tables, etc, so it will work with the plugin.
 * I’ve been able to do so with EM_Location->save() and EM_Location->save_meta(),
   and adding the post metadata with add_post_meta().
 * What I need to do now is to use EM_Location->save and leave the post as pending,
   not as published. EM_Location->post_status = ‘pending’ does not work.
 *  Plugin Support [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * (@angelo_nwl)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-location-data-with-functions/#post-4486963)
 * you can try to hook into em_location_set_status filter for this. for reference
   only, this is located under classes/em-location.php at around line 486 – 514
 *  Thread Starter [txemaleon](https://wordpress.org/support/users/txemaleon/)
 * (@txemaleon)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-location-data-with-functions/#post-4487032)
 * And is there any easy way to do this? I’m trying to do
 *     ```
       $EM_Location->set_status(0);
       $EM_Location->save();
       $EM_Location->save_meta();
       ```
   
 * But this is not working, nor is $EM_Location->set_status(‘pending’);
 *  Thread Starter [txemaleon](https://wordpress.org/support/users/txemaleon/)
 * (@txemaleon)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-location-data-with-functions/#post-4487033)
 * Well, I found a patch solution, which is immediately after save_meta() downgrade
   the post to pending:
 *     ```
       $EM_Location->save();
       $EM_Location->save_meta();
       wp_update_post( array( 'ID' => $EM_Location->post_id, 'post_status' => 'pending' ) );
       ```
   
 * I find this to be the most elegant solution besides making the save in pending
   status. Not ideal though, if you can point me to something better, I’d thank 
   you.

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

The topic ‘Insert location data with functions’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

## Tags

 * [plugin-development](https://wordpress.org/support/topic-tag/plugin-development/)

 * 5 replies
 * 3 participants
 * Last reply from: [txemaleon](https://wordpress.org/support/users/txemaleon/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/insert-location-data-with-functions/#post-4487033)
 * Status: resolved