Title: Incorrect $post variable breaks plugin
Last modified: August 31, 2016

---

# Incorrect $post variable breaks plugin

 *  [bkonia](https://wordpress.org/support/users/bkonia/)
 * (@bkonia)
 * [10 years ago](https://wordpress.org/support/topic/incorrect-post-variable-breaks-plugin/)
 * Some plugins mess with the global $post variable, resulting in it reporting a
   post type of “page”, for custom post types. This breaks your plugin because when
   it looks up the template for a custom post type page, it’s looking in the wrong
   category. The simplest way to work around this is rather than using the $post
   variable directly, do an additional lookup via the post ID.
 * $post_type = get_post_type($post->ID)
 * By the way, this issue is being tracked on github by another plugin developer:
 * github.com/mtekk/Breadcrumb-NavXT/issues/145
 * [https://wordpress.org/plugins/custom-post-type-page-template/](https://wordpress.org/plugins/custom-post-type-page-template/)

The topic ‘Incorrect $post variable breaks plugin’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-post-type-page-template_fcfcfc.
   svg)
 * [Custom Post Type Page Template](https://wordpress.org/plugins/custom-post-type-page-template/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-post-type-page-template/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-post-type-page-template/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-post-type-page-template/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-post-type-page-template/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-post-type-page-template/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [bkonia](https://wordpress.org/support/users/bkonia/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/incorrect-post-variable-breaks-plugin/)
 * Status: not resolved