I am trying to add custom meta and see at “Preview Changes”. I can see the changes but also changes apply to the actual post at Front end. I want the changes will update to the actual post when it Publish or Update not at “Preview Changes” click. Please help.
I have followed this plugin.
function my_plugin_save_post( $post_id, $post ) {
if ( $parent_id = wp_is_post_revision( $post_id ) ) {
$parent = get_post( $parent_id );
$my_meta = get_post_meta( $parent->ID, 'my_meta', true );
if ( false !== $my_meta )
add_metadata( 'post', $post_id, 'my_meta', $my_meta );
}
} add_action( ‘save_post’, ‘my_plugin_save_post’ );
The following code will prevent your meta data from saving on preview but You won’t be able to preview published posts with your metadata. Honestly I’m trying to figure out this situation myself :/
Honestly, I’d use this code and set your post briefly to
draft
orprivate
while editing / previewing and publish them as normal when you’re done.