If you look at the source and the Codex page for get_post_type you will see that returns the type of the “current post” unless you pass it a post ID or post Object. get_post_type should work without a parameter if you are running that code on the post edit page(s) generated by WordPress for post types. Anywhere else and that is not guaranteed. It isn’t possible to give you specifics because your questions doesn’t contain specific enough information, but I am fairly sure that is the problem you are having with the code.
That said, @WPThemes is right. That check is not necessary. That answer should probaly solve things for you (so pick it).
Additional notes: If you register your metaboxes on a callback (@WPThemes’ answer) when you register the post type you can dispense with the is_admin check. The boxes will register when they are needed. you can also hook directly to add_meta_boxes_{post-type}.
Related Posts:
- Tips for using WordPress as a CMS? [closed]
- Custom Post Type Templates from Plugin Folder?
- How to Remove Certain Screen Options and Meta Boxes from add/edit post type?
- Creating a default Custom Post Template that a Theme can override
- Jetpack plugin (ShareDaddy): Prevent share buttons showing on custom post types?
- How to make a list of companies’ information and display them to user, using custom post types and a custom taxonomy?
- Seriously stuck with some custom meta box/plugin stuff
- remove custom taxonomy metabox form custom post type
- [Plugin: Posts 2 Posts] reciprocal connections
- Custom Post Type Statuses
- How to Build a Movie Library in WordPress 3.x
- How do I get multiple pages by title?
- add_meta_box Callback not being called
- I need to add a custom “cover” to every new post — plugin or custom setup?
- Star rating for custom post types [closed]
- How to Make a Custom Grid View
- Get image URL from media library in input
- Way to hook into a sidebar call to replace it with a custom sidebar
- wordpress reusable content blocks
- Allow users mark posts as “complete”?
- Is there a way to order posts and custom post types as one group?
- how do i remove posts from a WP_Query so the pagination is right?
- dynamically generating plugin syntax
- Duplicate posts when posting nulls in records in phpMyAdmin [closed]
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- Accessing post’s meta data based on user’s click of a post
- Plugin custom post type – Internal server Error
- Exclude post by custom meta with pre_get_posts
- Is it possible to create Custom Post plug-in?
- List taxonomy terms for post as checkboxes
- When using Simple Fields plugin, how do I pull the information out of the database to display on a page?
- How to make a proper custom post type link
- Matching Chapters to a Custom posts [closed]
- Mq translate plugin custom post type issue
- ACF: post query, hide duplicate values [closed]
- What is the best way for showing a grid of customer logos?
- WordPress custom taxonomy not showing
- Using ACF default value to autoincrement a number field
- How to Resize the Custom Post Images?
- Amazon.com intergration with WordPress?
- Trying to add a page template for my custom post type from a plugin, but it will not display in the template dropdown unless file is in theme
- Adding custom meta boxes to specified custom post type
- How do I make reusable content blocks for header and footer when using WordPress headless with another front-end?
- posts from multiple post types in one slider
- Custom Post Type – custom form in dashboard
- $pages = get_pages(‘child_of=’.$post->ID); Why arguments are concatenated?
- WP-API Custom Post Type json_no_route
- How can I list custom post type categories of portfolio
- How can I store data from custom fields to custom tables?
- Plugin generated unexpected output – No PHP errors
- Custom post type change excerpt more and excerpt length
- Use jQuery Datepicker code from plugin
- Order posts of a custom post type by the event date using FT Calendar Plugin
- Posts 2 Posts: Display custom types connected to the same other custom type but with another connection
- Creating teams of users in WordPress
- hardcoded wp pages/plugins problems
- Including content from legacy app: via plugin or custom content?
- How display specific category post to specific users?
- Dictionary-style definition list plugin
- Error Metabox Warning: call_user_func() expects parameter 1 to be a valid callback
- Need to edit author permissions | custom taxonomy
- Import Recent Posts Only and Ignore old ones if exist
- Is it possible to pin a post in second position from top
- WordPress REST API: Query media files attached to a custom post type
- Save log for imports in WordPress database – options-table, custom post type or other place?
- How to get the custom field value using SQL query
- How to display emails as a post?
- Create category for each user
- Error in Fetching Custom Post Type parent Category URL (slug)
- How to display the category name in the tab and post inside the tab in WordPress?
- Want to build parent-child relationships between custom post types created with CPT UI
- Hidden permalink different from displayed permalink
- custom post type plugin error [closed]
- Add an action based on custom post meta field
- Merging new theme and plugins from development site to production
- Ultimate Members Default Post Layout problem
- how to convert frontpage.php to dynamic page?
- Creating custom “player-objects”
- Is it possible to customize a wordpress post from outside dashboard(Something like site.com/post-type/post/?e=post_id)?
- Calling an custom field from theme option at the frontend
- Hide some portion on single.php base on author
- Creating themes using the one Plugin (Toolkit)
- Displaying image from a repeatable group
- How to add jquery to my custom post type wp plugin
- WordPress list child pages of custom post type
- CPT-onomies CPT_TAXONOMY->get_terms extremely slow with 6K posts
- get recent 12 days post then random in wordpress
- What method should I use for a sidebar widget that reads latest posts?
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- WordPress Custom post type won’t save properly
- Making a Custom Post Type Publish Loop
- WordPress User Frontend Editing Custom Fields
- Is a custom post type considred a plugin?
- Remove base from the custom post type URL [duplicate]
- Make a magic tag work with Custom Post Types
- How to laod wp_enqueue_style to another header i created my self
- Links not opening as they should. Custom WP plugin
- How to make content as required in custom post type?
- How to provide page_template path in custom plugin using WordPress
- How do I know if an archive correspond to a custom post type taxonomy?