k-isabelle
5/31/2018 - 4:29 PM

Append post meta to the content (post_content) (uses 'wp_insert_post_data')

Append post meta to the content (post_content) (uses 'wp_insert_post_data')

<?php 

//----------------------------------------------
//  Filter Post Data
//----------------------------------------------
/* The purpose of this filter is to take the 
/* post meta from a custom field and save it 
/* into post_content */

// Tack our filter onto the wp_insert_post_data action
add_filter( 'wp_insert_post_data', 'my_appender' );
function my_appender( $content ) {
  // Bring global $post into scope
  global $post;
  // Get meta value of meta key 'key_name'
  $meta_value = get_post_meta( $post->ID, 'my_meta_key', TRUE );
  // If value is not in content, append it onto the end
  if ( stristr( $content['post_content'], $meta_value ) === FALSE )
    $content['post_content'] .= $meta_value;
  // Return filtered content
  return $content;
}

/* Source: http://wordpress.stackexchange.com/questions/51618/appending-meta-value-onto-post-content-in-wordpress-during-save-post */

?>