Last active
January 3, 2016 15:29
-
-
Save kisabelle/8482974 to your computer and use it in GitHub Desktop.
Append post meta to the content (post_content) (uses 'wp_insert_post_data')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 */ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: http://wordpress.stackexchange.com/questions/51618/appending-meta-value-onto-post-content-in-wordpress-during-save-post