Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am loading scripts for a custom post type with a function like this :

   global $post_type;
    if( 'portfolio' == $post_type )
    wp_enqueue_script( 'maps_scripts',  get_bloginfo('template_directory') . '/scripts/maps.js');

This works fine when I am added a new post in that post type :

post-new.php?post_type=portfolio

but when I go to edit one with this link

post.php?post=541&action=edit

I lose the portfolio parameter and also those scripts. How can I fix?

share|improve this question

closed as too localized by toscho Mar 2 at 23:51

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

2 Answers

Try:

global $post;
if( 'portfolio' == $post->post_type )
share|improve this answer

Try using get_post_type.

global $post;
global $post_type;
if((get_post_type($post->ID) == 'portfolio') || ('portfolio' == $post_type)) {
    wp_enqueue_script( 'maps_scripts',  get_bloginfo('template_directory') . '/scripts/maps.js');
}
share|improve this answer
thanks but that made no difference – zac Jan 2 '12 at 22:40
You may have to set the post_id. I have updated the code above. – imHavoc Jan 2 '12 at 22:54
nope, still doesnt work when i try and go back to edit, i lose those scripts. Does it seem weird to you that I lose the ?post_type parameter when I go to edit or is that expected? – zac Jan 2 '12 at 23:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.