The fourth parameter is $screen
, which in your case is set to post
, so all you have to do is specify the website
post type instead:
function website_add_meta_box() {
add_meta_box(
'website-website',
__('Website', 'website'),
'website_html',
'website',
'normal',
'default'
);
}
Documentation here: https://developer.wordpress.org/reference/functions/add_meta_box/
As an aside, your save_post
hook applies to any post or custom post type being saved, but if website_website_url
and website_website_source_code
only apply to the website
post type, you can add an additional check:
function website_save($post_id) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (!isset($_POST['website_nonce']) || !wp_verify_nonce($_POST['website_nonce'], '_website_nonce' )) return;
if (!current_user_can('edit_post', $post_id)) return;
if (get_post_type($post_id) !== 'website') return;
if (isset($_POST['website_website_url']))
update_post_meta($post_id, 'website_website_url', esc_attr($_POST['website_website_url']));
if (isset($_POST['website_website_source_code']))
update_post_meta($post_id, 'website_website_source_code', esc_attr($_POST['website_website_source_code']));
}