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
- How to automatically update ACF field value every year?
- Adding Show Less/More link to Custom Post Meta
- Returning a list of custom post types excluding those without a specific meta_value
- Want to Add Custom Fields for Uploading video to WordPress Users from front end
- Keep display metadata value on backend – Custom Metabox
- How to bulk copy custom fields between custom posts?
- Show the same Article Available in Other Categories
- Getting posts under the custom post type ui category
- Sorting custom post type columns with external data and without meta values
- Storing posts from query and accessing later via AJAX call
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- If post has custom field then display css-class
- Meta Key Value in current-user-only loop
- Retrieve value of a category’s custom field
- Calculate all custom field values in the post loop
- Rewrite and custom post type: order by custom field not working
- add custom field to custom post type
- How to set up multisite for multi language?
- CPT Group by Date metabox Value
- How to check if user meta field is empty in conditional else statement
- Replace text in post from cvs
- Admin search ACF relationship
- Display only one post each WEEK
- wp_query check if integer exists in custom field’s array
- List children on child post
- How can I dynamically add a post to a custom post type which uses a custom field?
- Restrict custom post type from appearing with ?post_types=
- Show custom post type filtered by category
- Filtering custom post type on a combination of custom taxonomies and custom fields?
- Custom Posts Types as Custom Fields
- create parent post using wp_insert_post
- Get image post ID in media upload
- Turn on and off custom post type from admin?
- Missing Posts in Custom Taxonomy List
- Display random posts, but omit the post it is on?
- Why is my select meta data not saving?
- How do I do this with WordPress? Taxonomies?
- dynamically add a custom field or metabox to custom post type [duplicate]
- Give a permalink to Custom Post Types without title
- Disable block with taxonomies at post page
- Role scoping for contributors down to the field level
- How to implement a Google map store locator
- I would like to have different styles for my posts based on the content of each post
- Creating a Custom Post as a repository for theme constants
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- search also in taxonomy, tags and custom fields
- Random image from tag/custom type on sidebar
- Showing posts from different categories and from custom post type
- Get latest 3 posts from multiple CPT in one query
- How to stick custom post at the top in search results
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Which post does a taxonomy term belongs to?
- How do I create custom fields for multiple post types?
- Add field to all custom post types
- List custom taxonomy specific to one custom post type
- Query & Order posts by custom fields
- Filter custom posts using auto populated dropdown selectors
- Post image in WordPress not appearing on home page
- How do I associate a custom post type with another through a taxonomy or storing an ID in a custom field?
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Custom post type content using custom fields without template
- Meta query for custom post type ignored in main query
- Changing custom type name hides the posts
- Cannot add custom field to “orderby” parameter in Rest API
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Display Ad on Specific Categories
- retrieve Meta field value from CPT and set those values as Image Meta Field “Title”
- Having unique constraints for custom fields in a custom post type
- Hiding posts by other users and non-logged in
- Querying Two Custom Post Types with OR Not Working
- How can I get the number of custom post type posts that have a specific attachment image set?
- Trash / Draft a WordPress custom post after custom date field expires
- Set a maxlength for the title input in a custom post type
- Posting to a Custom Post Type from front end – user generated content