public
Created

Populate editorial metadata fields when creating a new post

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?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.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.