Yes, you are doing it wrong. You are checking for the posts’ custom field value which the new post page will does not have, and editing older posts might also does not have the custom field set or may be set to an empty value.
Yes, you need to check for the custom post type:
if ( is_admin() && ( $post->post_type == "customType" ) {
wp_register_style('admin_js', get_bloginfo('template_directory') . '/admin.js');
wp_enqueue_script('admin_js');
}
Related Posts:
- Enable sticky posts to custom post_type
- How can I add a column/s to wp_posts table?
- How to hook get_terms() to only show count of posts that have custom meta
- add_meta_box: Datepicker like the one for postdate?
- Multiple information using custom post type
- Before Delete Post
- How to use custom fields to enable sticky posts on custom post types?
- Adding dropdown select meta box to custom post type – seems restAPI is interfering
- Update Post Meta for a logged in user
- Add custom field to Posts and sort by it
- Two Custom Post Types Many to Many Relationship
- How to integrate a form (Ninja Form or Contact Form 7) with Custom Post Types?
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Conditional for a Single Post That Belongs to a Category?
- Modify Posts from Custom_Post_Type within the plugin
- Making a form for user to add new custom post with custom taxonomies and custom fields
- Front-end Image Upload to Custom Meta Box
- A sports wordpress website
- Display custom post front end filter by ACF equals current user
- How to display custom field in product description?
- Show posts from WP Custom Post Type selected from a field in a metabox
- WP_posts (Not meta) extra custom field column show and change it in a custom post type
- Multiple domains, Single database, 1 Parent/Master with all content, other domains/slaves with filtered content (based on “location” variable)
- Calling specific page with wp query
- custom field suit new post with in custom fields
- Display code if title of the custom post matches title of other post
- Advanced search form with filters for custom taxonomies and custom fields
- Custom field values deleted when trashing custom post type
- WordPress REST Create Post of Custom Type
- Limit the post for differents custom post type in the same wp_query
- order by meta_value serialized array
- Custom post metadata not appearing in public API
- Multiple Content Block
- Display Custom Post Type in Recent Posts
- Slug for standard post post_type
- How do I create an archive page for standard posts?
- Remove parent from custom post type
- How to add the post ID (or any other post data) to a Contact Form 7 mail?
- Create a post in custom post type using field in registration form after users submit form
- How to add post_type=value when editing that post type in the WordPress admin?
- Publish an XML feed from a CPT with ACF fields?
- Want to Add Custom Fields for Uploading video to WordPress Users from front end
- Custom Posts Types as Custom Fields
- dynamically add a custom field or metabox to custom post type [duplicate]
- retrieve Meta field value from CPT and set those values as Image Meta Field “Title”
- Disable saving posts as draft (make all posts mandatory regardless of the post status)
- Woocommerce custom field search in custom post type [closed]
- Prioritize posts in query by meta keys?
- Meta Query posts not showing on ending date of custom field
- Load Next Posts With AJAX not working with custom post type
- Custom Post Fields at the beginning of a Custom Permalink
- Possible to filter custom post type with multiple meta data?
- Create custom post with meta field with AJAX and the WordPress REST API
- Specifying meta field’s column type in Database using add_post_meta
- Creating custom post type with custom taxonomy and custom fields programatically
- wordpress lists similar type of posts in a custom post type
- Auto post creation
- posttype and custom fields on multisite
- How to fetch custom post types with its full data on wordpress?
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- list posts of two post types in a single template
- Order custom posts by taxonomy, then by meta_key
- Adding a Custom Field to be used by Posts 2 Posts
- redirect after submiting post for review
- i need to have a tab with gategory post
- Custom Post type to Woocommerce Product type
- Auto delete pages/posts without views
- Display Posts that fit a certain criteria on Category pages
- Filter posts by their related field’s custom field
- WordPress retrieving $post based on random key in $_POST
- How can I register multiple custom post fields to json?
- Sql Update CPT from publish to draft and particular custom field
- minimize wp_query call to database
- Post display in separate page [duplicate]
- Limit posts per page depending on the size of a div?
- sorting in wp query based on custom field value
- Delete Post by User
- PHP Notice: Unidentified index
- Setting up a page to house certain types of posts
- WordPress loop add heading before first of type
- How do i create user accounts from custom posts that have email addresses
- Only show current category post
- WordPress Contents Migration
- How to set class to “current-page” on the currently viewed single post within a CPT
- Best way to use Category & Custom Fields?
- How to make post page unique and show it on home page?
- How do I add custom fields to posts without having to manually add everytime I post?
- How to display custom post type ordered by a custom field date
- Is it good practice to search for custom posts based on custom field values?
- Custom post type with custom fields enabled, is there a way to set a default group of fileds?
- Storing/querying custom date data
- Query Posts From Multiple Post Types
- WP Build-In Post selector for CPT
- Custom Post Meta on a Different Page?
- Custom Post type easy way for editors
- How do I hide single category post on my post page
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Creating post custom field text area
- querying to custom field over ACF REST API
- How to make a non-public post on wordpress approval?