I created a client profile custom post type and have started creating the meta boxes and such for users to enter in information. While all of that seems to be working fine, when I go to save the custom post, nothing gets sent to the database. Here are my functions

Meta Box

function add_meta_boxes() {
    add_meta_box(
        'client-info',
        __( 'Client Information', 'textdomain' ),
        'meta_box_clientinfo_callback',
        'clientprofile',
        'normal',
        'high'
    );
}
add_action( 'add_meta_boxes', 'add_meta_boxes' );

Client Info Meta Box Callback

function meta_box_clientinfo_callback( $post )  {
    global $my_post_meta;
    $my_post_meta = get_post_meta( $post->ID );
    wp_nonce_field( plugin_basename( __FILE__ ), 'my-nonce' );
?>

    <p>Please enter in the information on the client whom you wish to feature in a case story.</p>
    <p>
        <label for="client-name"><?php _e( 'Client Name', 'textdomain' ); ?></label>
        <input type="text" name="client-name" id="client-name" value="<?php field_value( 'client-name' ); ?>" size="25" />
    </p>

    <p>
        <label for="client-age"><?php _e( 'Client Age', 'textdomain' ); ?></label>
        <input type="text" name="client-age" id="client-age" value="<?php field_value( 'client-age' ); ?>" size="3" maxlength="3" />
    </p>

    <p>
        <label for="client-gender"><?php _e( 'Client Gender', 'textdomain' ); ?></label>
        <select id="client-gender" name="client-gender">
            <option value="male">Male</option>
            <option value="female">Female</option>
            <option value="Other">Other</option>
        </select>
    </p>

<?php
}

Save Post

function save_meta( $post_id ) {

    // Verify Nonce
    if ( ! isset( $_POST['my-nonce'] ) || ! wp_verify_nonce( $_POST['my-nonce'], basename( __FILE__ ) ) ) {
        return;
    }

    if ( ! current_user_can( 'edit_post', $post_id ) ) {
        return;
    }

    if ( isset( $_REQUEST['client-name'] ) ) {
        update_post_meta( $post_id, '_client_name', sanitize_text_field( $_POST{'client-name'} ) );
    }

}
add_action( 'save_post'. 'save_meta', 10, 2 );

The field_value function I call in the callback is just a little helper I wrote that checks to see if $my_post_meta['$field_id'] is set and if so returns $my_post_meta['$field_id'][0].

What am I missing something here? I looked at several examples online to get the code I have now but when I look in PHPMyAdmin at the wp_postmeta table for the Post ID, I only see keys for _edit_last and _edit_lock.

Read more here: Custom Post Type Metadata Not Saving


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: