get_post_type() and WP_QUERY issue

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}.

tech