Selecting New & Edit Page for Custom Post Types
Question
I’m probably missing something unless it’s really not possible, for some reason I can’t get my function to only execute on the new and edit page of a custom post type (the new not being a problem):
I’m currently using:
if ((isset($_GET['post_type']) && $_GET['post_type'] == 'events') || (isset($post_type) && $post_type == 'tf_events')) {
add_action('admin_init', "admin_head");
}
However this only works for adding a new post where the URL is:
/post-new.php?post_type=events
But for editing a post it doesn’t work, where the URL is:
/post.php?post=12&action=edit
(although the post type isn’t added to the link attribute)
WORKING CODE (See Mark’s response below):
// 7. JS Datepicker UI
function events_styles() {
global $post_type;
if( 'tf_events' != $post_type )
return;
wp_enqueue_style('ui-datepicker', get_bloginfo('template_url') . '/css/jquery-ui-1.8.9.custom.css');
}
function events_scripts() {
global $post_type;
if( 'tf_events' != $post_type )
return;
wp_deregister_script('jquery-ui-core');
wp_enqueue_script('jquery-ui', get_bloginfo('template_url') . '/js/jquery-ui-1.8.9.custom.min.js', array('jquery'));
wp_enqueue_script('ui-datepicker', get_bloginfo('template_url') . '/js/jquery.ui.datepicker.min.js');
wp_enqueue_script('custom_script', get_bloginfo('template_url').'/js/pubforce-admin.js', array('jquery'));
}
add_action( 'admin_print_styles-post.php', 'events_styles', 1000 );
add_action( 'admin_print_styles-post-new.php', 'events_styles', 1000 );
add_action( 'admin_print_scripts-post.php', 'events_scripts', 1000 );
add_action( 'admin_print_scripts-post-new.php', 'events_scripts', 1000 );
0
custom-post-types, query
3 years
2020-05-29T23:10:22-05:00
2020-05-29T23:10:22-05:00 0 Answers
87 views
0
Leave an answer