How can I limit a wordpress meta_box to a single page?

I need a way to limit the meta box to a single page (ID=84) … if I do the following it works, but sbumit data does not go through and data is not saved …

add_action('admin_init','violin_init');

function violin_init()
{
    if ($_GET['post'] == '84')
    {
        wp_enqueue_style('violin_admin_css', VIOLIN_THEME_PATH . '/custom/meta.css');

        add_meta_box('violin_options_meta', 'Highlight Content', 'violin_options_meta', 'page', 'normal', 'high');

        add_action('save_post','violin_save_meta');
    }
}

Related posts

Leave a Reply

1 comment

  1. I’ve found a solution that works, but I wish there was a way through the wordpress API and/or one of wordpress’ globals …

    the following works:

    if ($_GET['post'] == '84' OR $_REQUEST['post_ID'] == '84')
    

    Additionally you can also filter by a specific template:

    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
    
    $template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
    
    if ($template_file == 'home.php') {} // by template file
    
    if ($post_id == 84) {} // by page ID
    

    I wrote a blog post on it: Page Specific WordPress Meta Box