Selecting New & Edit Page for Custom Post Types

Ok, total revision on my original answer, which just turned into a mess.

The issue with your code is that you’re firing on init, this covers every admin page, and additionally it’s too early to check admin vars to work out the current page(though you could just check $_GET if you really need to run code that early).

You want to specifically hook to the post edit pages, though you’ve not indicated you need to run on the post listing to(edit.php), so i’ll exclude that from the examples that follow.

You can hook to a few different actions that occur inside the admin head, and do whatever you need to do there and be able to reliably check the post type by giving $post_type scope inside your callback function.

So your callback would go a little something like this..

function mycallback() {
    global $post_type;
    if( 'events' != $post_type )
        return;
    // Do your code here
}

What action you want that hooked onto is down to what you want to run at that point, if you’re not doing anything in particular but want to execute something, then perhaps the generic admin head hook will be suitable..

add_action( 'admin_head-post.php', 'mycallback', 1000 );
add_action( 'admin_head-post-new.php', 'mycallback', 1000 );

If you’re loading a script, then you might use..

add_action( 'admin_print_scripts-post.php', 'mycallback', 1000 );
add_action( 'admin_print_scripts-post-new.php', 'mycallback', 1000 );

If you’re loading a stylesheet, then possibly..

add_action( 'admin_print_styles-post.php', 'mycallback', 1000 );
add_action( 'admin_print_styles-post-new.php', 'mycallback', 1000 );

Else i’ll need to know more about what you’re doing… 🙂