You have used $post
instead of $_POST
in save function. That is why data is not saved.
You have should use :
$_POST[ 'custom_meta2_nonce' ]
$_POST['sec_title']
$_POST['principle_duties']
instead of
$POST[ 'custom_meta2_nonce' ]
$POST['sec_title']
$POST['principle_duties']
Use below code to save data :
function custom_meta2_save($post_id){
//checks save status
$is_autosave = wp_is_post_autosave( $post_id);
$is_revision = wp_is_post_revision( $post_id);
$is_valid_nonce = ( isset( $_POST[ 'custom_meta2_nonce' ] ) && wp_verify_nonce( $_POST['custom_meta2_nonce' ],basename( __FILE__)) ) ? 'true': 'false';
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
//Exit scripts depending on save status
if( $is_autosave || $is_revision || !$is_valid_nonce ){
return;
}
if( isset( $_POST['sec_title'] ) ){
update_post_meta( $post_id , 'sec_title', sanitize_text_field( $_POST[ 'sec_title'] ) );
}
if( isset( $_POST['principle_duties'] ) ){
update_post_meta( $post_id , 'principle_duties', sanitize_text_field( $_POST[ 'principle_duties'] ) );
}
}
add_action('save_post', 'custom_meta2_save');
you can use custom page template file or page template file To display data in page:
$sec_title = get_post_meta( get_the_id(), 'sec_title', true );
$principle_duties = get_post_meta(get_the_id(), 'principle_duties', true);
echo "Secondary ID :".$sec_title;
echo "<br>Principle duties :".$principle_duties;