The dbx_post_advanced WordPress PHP action fires in the middle of built-in meta box registration.
Usage
add_action('dbx_post_advanced', 'my_custom_function');
function my_custom_function($post) {
// your custom code here
}
Parameters
$post(WP_Post) – The WordPress post object.
More information
See WordPress Developer Resources: dbx_post_advanced
Examples
Adding a custom meta box
Add a custom meta box to the post editing screen.
add_action('dbx_post_advanced', 'add_my_meta_box');
function add_my_meta_box($post) {
add_meta_box('my_meta_box', 'My Meta Box', 'display_my_meta_box', $post->post_type, 'normal', 'high');
}
function display_my_meta_box() {
// Display the meta box content
}
Displaying post ID
Display the post ID in a custom meta box.
add_action('dbx_post_advanced', 'add_post_id_meta_box');
function add_post_id_meta_box($post) {
add_meta_box('post_id_meta_box', 'Post ID', 'display_post_id', $post->post_type, 'side', 'default');
}
function display_post_id($post) {
echo 'Post ID: ' . $post->ID;
}
Adding custom content based on post type
Add custom content to the post editing screen based on post type.
add_action('dbx_post_advanced', 'add_custom_content');
function add_custom_content($post) {
if ($post->post_type == 'page') {
echo 'You are editing a page!';
} else {
echo 'You are editing a ' . $post->post_type . '!';
}
}
Conditionally adding a meta box
Add a custom meta box only if the post is a draft.
add_action('dbx_post_advanced', 'add_draft_meta_box');
function add_draft_meta_box($post) {
if ($post->post_status == 'draft') {
add_meta_box('draft_meta_box', 'Draft Info', 'display_draft_info', $post->post_type, 'side', 'default');
}
}
function display_draft_info() {
echo 'This post is a draft.';
}
Hiding a meta box based on user role
Hide a meta box for users who are not administrators.
add_action('dbx_post_advanced', 'hide_meta_box_for_non_admins');
function hide_meta_box_for_non_admins($post) {
if (!current_user_can('manage_options')) {
remove_meta_box('slugdiv', $post->post_type, 'normal');
}
}