0

When I'm updating a post, its content is being cleared. What's wrong with the code below?

add_action( 'save_post', 'eb_save_subpage_data' );
function eb_save_subpage_data() {
    global $post;

    if ( $post->post_type == 'subpage' ) {
        update_post_meta( $post->ID, 'title_pl', esc_attr( $_POST['meta_input_title_lang_pl'] ) );
        update_post_meta( $post->ID, 'title_en', esc_attr( $_POST['meta_input_title_lang_en'] ) );
        update_post_meta( $post->ID, 'title_ru', esc_attr( $_POST['meta_input_title_lang_ru'] ) );

        remove_action( 'save_post', 'eb_save_subpage_data' );
        wp_update_post( array(
            'ID' => $post->ID, 
            'post_title' => esc_attr( $_POST['meta_input_title_lang_pl'] ),
            'post_name' => sanitize_title( $post->post_title )
        ) );
        add_action( 'save_post', 'eb_save_subpage_data' );
    }
}
0

You can modify your code:

add_action( 'save_post_subpage', 'eb_save_subpage_data' );
function eb_save_subpage_data( $post_id ) {

You have to use this action to add custom fields, default post data are saved automatically.

| improve this answer | |
  • This makes no difference. I would like to update default post data like title - without content - but the content disappears somewhere. – Damian Czapiewski Oct 5 '14 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.