add_meta_boxes_{$post_type}

最后更新于:2021-11-25 19:12:05

do_action( “add_meta_boxes_{$post_type}”, GC_Post $post )

Fires after all built-in meta boxes have been added, contextually for the given post type.

参数

$post

(GC_Post)
Post object.

源文件

文件: gc-admin/includes/meta-boxes.php

View on Trac

/**
 * Register meta box(es).
 */
function gcdocs_register_meta_boxes() {
    add_meta_box( 'meta-box-id', __( 'My Meta Box', 'textdomain' ), 'gcdocs_my_display_callback', 'post' );
}
add_action( 'add_meta_boxes', 'gcdocs_register_meta_boxes' );
 
/**
 * Meta box display callback.
 *
 * @param GC_Post $post Current post object.
 */
function gcdocs_my_display_callback( $post ) {
    // Display code/markup goes here. Don't forget to include nonces!
}
 
/**
 * Save meta box content.
 *
 * @param int $post_id Post ID
 */
function gcdocs_save_meta_box( $post_id ) {
    // Save logic goes here. Don't forget to include nonce checks!
}
add_action( 'save_post', 'gcdocs_save_meta_box' );