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:
- Adding a Taxonomy Filter to Admin List for a Custom Post Type?
- Implementing a CrunchBase.com Clone using WordPress?
- Custom media upload content for inserting custom post shortcode
- How to share category taxonomy with custom post type (The Event Calendar plugin)
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- How to get a variable number of posts per post type on the main loop?
- WP_query parameters for date range
- Use a plugin to handle custom post types?
- Register Custom Post Type from Plugin
- Prevent page slug from interfering with custom post type archive permalink?
- Add .html extension to custom post type taxonomies
- How to load a new template page according to a particular URL?
- How to get the custom page get_permalink?
- Updating post meta for custom post types
- Template for custom post type shows all posts instead of just one
- Custom Post Type causes Page Not Found
- Plugin “Meta Box”: Implementing meta boxes in custom post type
- Frontend editing, Frontend user dashboard
- Plugin allowing for artists, events and venues
- custom taxonomy and custom post type url conflict
- Override plugin with functions.php
- Should i delete the posts created by a plugin on uninstall?
- RW Meta Box ,Problem setting post title
- How does WP handle multiple matching rewrite rules?
- Saving Custom Post types and fields to a custom table
- Is it possible to use WordPress as an online portfolio for text content? What kind of theme would I look for?
- Building a store locator with google maps
- How to make wp_enqueue_style and wp_enqueue_script work only on custom post type
- How to create user groups and allow custom posts and plugin modify/access to specific group?
- Correct way to make meta box with more than one meta field secure
- I want to extend the current themes’ single.php to display the meta fields of my CPT
- How can I create a custom shortcode that will return a custom post type by ID?
- get_post_type on post.php
- All of my custom posttypes are 404’ing
- more types plugin – display all post of post type on page
- ‘No Results Found’ on single post for custom post type
- Making a Template for a CPT created by a plugin
- auto populate list of questions if user select a category xyz
- “Custom Post Type Permalinks” plugin URL strcuture
- Adding CSS to custom post type admin page causes error
- ACF: post query, hide duplicate values [closed]
- Redirect to another page using contact form 7? [closed]
- Custom Post Type Fields
- Custom setup of wordpress comments that are displayed
- publish_post action doesn’t work
- Disable Individual Plugins (specifically in Custom Post Types) on a per-post basis?
- custom post type don’t appear in the home page
- Amazon.com intergration with WordPress?
- Sticky option for custom post types without using custom fields or plugins
- 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?
- How do we update a custom file upload field with the Advanced Custom Field plugin?
- Preview with Custom Post Type Not Working
- How can I store data from custom fields to custom tables?
- 2 wordpress site same database
- How to Include Custom Post Content From Plugin
- Custom Template for wordpress cpt plugin
- Custom post type change excerpt more and excerpt length
- What hook can I use to modify custom post data before it is displayed on the page?
- Order posts of a custom post type by the event date using FT Calendar Plugin
- Custom Post Type template for homepage
- hardcoded wp pages/plugins problems
- How display specific category post to specific users?
- Rename existing cpt and taxonomy with new textdomain
- Best method of implementing compartmentalized custom post types on a multi-site network
- Need to edit author permissions | custom taxonomy
- Is it possible to pin a post in second position from top
- How to search post titles with whole words only, but not the exact word only?
- Remove custom taxonomy name from the slug – Custom Post Type UI
- Error in Fetching Custom Post Type parent Category URL (slug)
- Register PODS Custom Field with WPGraphQL [closed]
- Hidden permalink different from displayed permalink
- Can i stream data to a custom_post_type?
- Is there a hook similar to “save_post” which only fires AFTER the post is completely published?
- Adding custom post category to categories widget
- Custom Post Type with Sequence ID
- How to arrange custom posts in the backend/admin by custom taxonomy
- Adding LOAD MORE on a page
- save_post hook partly firing in update post
- custom post type get_posts() function not work
- Create multiple posts when a custom post is created
- how to convert frontpage.php to dynamic page?
- Cannot view Custom Post Type no matter what I try
- Page not found after creating the add new post slider using custom post type
- Displaying image from a repeatable group
- CPT-onomies CPT_TAXONOMY->get_terms extremely slow with 6K posts
- Custom Post type plugin breaking the front page shows dashboard?
- Insert data in custom table during new post creation
- Top Contributors Plugin with Custom Post Type
- How can i do custom author list?
- featured image problem with custom post type
- How to list the categories by custom taxonomy created?
- Is an Office a custom post type [closed]
- Snippet displaying LearnDash parent course title with lesson title [closed]
- Looking for a plugins for organization portal (Staff, Units, Departments)? [closed]
- Filter custom post type returned from REST api
- Wrong block appender button showing
- Select posts from list and add them in a new list
- Failed to update a post when I add a taxonomy to it
- How to make content as required in custom post type?