Function get_the_category doesn't work as expected with custom post types
|Reported by:||bjdj||Owned by:|
On a category page, the function 'get_the_category()' does not work as expected, combined with custom post types.
If a category has no posts assigned to it, 'get_the_category()' will return an empty array (probably because the global $post variable is empty as well?). If your WordPress installation only uses custom post types (like mine), and never uses the post_type 'post', this could be a problem.
I think I found an easy, not very beautiful, workaround for this problem; assign a post, which has post_type 'post', to all categories. That way, 'get_the_category()' returns an array with information.
Change History (9)
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from new to closed