public
Created

WordPress Filter content_save_pre

  • Download Gist
content_save_pre.php
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 30
/**
* The content_save_pre filter takes the data posted in the content window and allows for it to be edited
*/
 
// Generic code to run the filter
add_filter( 'content_save_pre', 'custom_content_save_pre' );
function custom_content_save_pre( $post_content ) {
 
// $post_content is what was posted to the edit form
// Edit it as needed then return it back to WordPress
 
return $post_content;
 
}
 
// Code used to save all $_POST info to the content area if the case-studies post type was saved
add_filter( 'content_save_pre', 'pjiag_content_save_pre' );
function pjiag_content_save_pre( $post_content ) {
 
if( $_POST['post_type'] == 'case-studies' ) :
$content = '';
foreach( $_POST as $k => $v ) :
$content.= $v . ' ';
endforeach;
 
return $content;
endif;
 
return $post_content;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.