I have a custom post type for testimonials which work like I expect it to. Below is a snippet of code for testimonials

add_action( 'init', 'register_cpt_testimonial' );
function register_cpt_testimonial() {

    ...

    $args = array( 
        ..
    );

    register_post_type( 'testimonial', $args );
}

However, now I want to be fancy and add meta boxes, but I cannot get it to show.

function testimonial_meta_boxes() {
    add_meta_box( 'testimonial_form', 'Testimonial Details', 'testimonial_form', 'testimonial', 'side', 'high' );
}

function testimonial_form() {
    $post_id = get_the_ID();
    $testimonial_data = get_post_meta( $post_id, '_testimonial', true );
    $client_name = ( empty( $testimonial_data['client_name'] ) ) ? '' : $testimonial_data['client_name'];

    wp_nonce_field( 'testimonial', 'testimonial' );
    ?>
    <p>
        <label>Client's Name (optional)</label><br />
        <input type="text" value="<?php echo $client_name; ?>" name="testimonial[client_name]" size="40" />
    </p>
    <?php
}

Can someone please explain what I’m missing here. I’m reading https://developer.wordpress.org/reference/functions/add_meta_box/ but I just don’t get what I’m missing.

Read more here: Custom Meta Box for Testimonials Custom Post Type


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: