A bugfix for custom post type / taxonomy issues
-
Hi guys,
This bug applies to the current (1.4) and previous (1.3) versions.
I’m using custom post types and taxonomies, and have sidebars that should only appear on individual posts with a particular custom category of a custom post type. (In other words, in the Conditions tab, I select “Taxonomy Terms”, then click the “[Custompost] Categories” link (where “Custompost” is a custom post type), then tick the checkbox of the required custom category.
This works in some cases but doesn’t in others. Here’s a bugfix to classes/class-woo-conditions.php (v 1.4.1) to make it function properly, starting from line 383:
// In Category conditions. /* CHANGED FOR BUGFIX $categories = get_the_category( get_the_ID() ); if ( is_array( $categories ) && ! is_wp_error( $categories ) && ( 0 < count( $categories ) ) ) { foreach ( $categories as $k => $v ) { $this->conditions[] = 'in-term-' . $v->term_id; } } */ $categories = get_the_category( get_the_ID() ); if ( ! is_wp_error( $categories ) && ( count( $categories ) > 0 ) ) { foreach ( $categories as $k => $v ) { $this->conditions[] = 'in-term-' . $v->term_id; } } if (is_admin()) { //$categories = get_the_category( get_the_ID() ); if ( ! is_wp_error( $categories ) && ( count( $categories ) > 0 ) ) { foreach ( $categories as $k => $v ) { $this->conditions[] = 'in-term-' . $v->term_id; } } } else { $terms = wp_get_post_terms(get_the_ID(), get_post_type().'_category' ); if ( ! is_wp_error( $terms ) && ( count( $terms ) > 0 ) ) { // Use custom taxonomy terms foreach ( $terms as $k => $v ) { $this->conditions[] = 'term-' . $v->term_id; } } else { // Use category $categories = get_the_category( get_the_ID() ); if ( ! is_wp_error( $categories ) && ( count( $categories ) > 0 ) ) { foreach ( $categories as $k => $v ) { $this->conditions[] = 'in-term-' . $v->term_id; } } } } // END CHANGED FOR BUGFIX
Hope this can help somebody having similar issues, and hope it can be integrated into future releases so I don’t have to keep patching them ??
Cheers,
Kona
- The topic ‘A bugfix for custom post type / taxonomy issues’ is closed to new replies.