Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created January 20, 2012 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbachhuber/1649460 to your computer and use it in GitHub Desktop.
Save danielbachhuber/1649460 to your computer and use it in GitHub Desktop.
Populate editorial metadata fields when creating a new post
<?php
/**
* A quick snippet to indicate how you might be able to populate Edit Flow editorial metadata fields when creating a new post
* Please keep in mind: I haven't tested this code, so it may need a bit of fixing before it actually works
*
* @see http://wordpress.org/support/topic/plugin-edit-flow-auto-populate-editorial-metadata-using-wp_insert_post
*/
// ... All of your form processing to prepare the data for wp_insert_post()
$post_id = wp_insert_post( $my_new_post_array );
// Save some of the form data as editorial metadata if Edit Flow is active and the module is enabled
global $edit_flow;
if ( $post_id && is_object( $edit_flow ) && $edit_flow->helpers->module_enabled( 'editorial-metadata' ) ) {
// Save an email address submitted in the form to an editorial metadata term with slug 'email-address'
// First we sanitize the data, then we get the term, then we get the term's postmeta key, and then
// we save the data to our newly created post
$email_address = sanitize_email( $_POST['form-email-address'] );
$email_address_term = $edit_flow->editorial_metadata->get_editorial_metadata_term_by( 'slug', 'email-address' );
$email_address_key = $edit_flow->editorial_metadata->get_postmeta_key( $email_address_term );
update_post_meta( $post_id, $email_address_key, $email_address );
// If you want to save data for more editorial metadata terms, you'd basically want to
// repeat the code for each form field
}
// ... do whatever else you need to do after saving your editorial metadata term data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment