How to show custom data on custom post type admin screen edit page?

I have created form for enquiry. When user fill this form then I am saving it into database as a custom post type. In backend I need to show extra information on custom post edit page. But did not find any hook.

I have tried this code:

Read More
[![function add_extra_info_column( $columns ) {
    return array_merge( $columns, 
        array( 'sticky' => __( 'Extra Info', 'your_text_domain' ) ) );
}
add_filter( 'manage_posts_columns' , 'add_extra_info_column' );][1]][1] 

But it adds a new column in custom post.

I need to show extra info when we click on edit page link for every post.

Related posts

Leave a Reply

1 comment

  1. This is just an example and you have to customize it for your needs:

    First step: Adding Meta container hook to backend (for example here for products post type):

    add_action( 'add_meta_boxes', 'extra_info_add_meta_boxes' );
    if ( ! function_exists( 'extra_info_add_meta_boxes' ) )
    {
        function extra_info_add_meta_boxes()
        {
            global $post;
    
            add_meta_box( 'extra_info_data', __('Extra Info','your_text_domain'), 'extra_info_data_content', 'product', 'side', 'core' );
        }
    }
    

    (replace 'product' by your post type and this meta box could be like here on 'side' or by ‘normal’ to get it on main column)

    Second step: Adding information in this metabox (fields, data, whatever…)

    function extra_info_data_content()
    {
        global $post;
        // Here you show your data  <=====
    
    }
    

    References:


    Third step (optional): Save the data of the custom meta post (needed if you have some fields).

    add_action( 'save_post', 'extra_info_save_woocommerce_other_fields', 10, 1 );
    if ( ! function_exists( 'extra_info_save_woocommerce_other_fields' ) )
    {
    
        function extra_info_save_woocommerce_other_fields( $post_id )
        {
            // Check if our nonce is set.
            if ( ! isset( $_POST[ 'extra_info_other_meta_field_nonce' ] ) )
            {
                return $post_id;
            }
            $nonce = $_REQUEST[ 'extra_info__other_meta_field_nonce' ];
    
            //Verify that the nonce is valid.
            if ( ! wp_verify_nonce( $nonce ) )
            {
                return $post_id;
            }
    
            // If this is an autosave, our form has not been submitted, so we don't want to do anything.
            if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
            {
                return $post_id;
            }
    
            // Check the user's permissions.
            if ( 'page' == $_POST[ 'post_type' ] )
            {
                if ( ! current_user_can( 'edit_page', $post_id ) )
                {
                    return $post_id;
                }
            }
            else
            {
                if ( ! current_user_can( 'edit_post', $post_id ) )
                {
                    return $post_id;
                }
            }
            /* --- !!! OK, its safe for us to save the data now. !!! --- */
    
            // Sanitize user input and Update the meta field in the database.
        }
    }