Opened 11 years ago
Closed 11 years ago
#25341 closed defect (bug) (fixed)
multiple custom post types in pre_get_post filter break body_class
Reported by: | norcross | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 3.7 | Priority: | normal |
Severity: | normal | Version: | 3.1 |
Component: | Template | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Issue: when viewing a custom post type archive template, and having added a pre_get_posts filter to display two separate custom post types on that page, the body_class function breaks trying to process an array to string conversion
Attachments (2)
Change History (14)
#2
@
11 years ago
- Keywords commit added; 2nd-opinion needs-testing removed
- Milestone changed from Awaiting Review to 3.7
- Version changed from trunk to 3.1
25341.diff is a simplified version.
#3
@
11 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 25471:
#4
@
11 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
is_post_type_archive() is not supposed to return true when there are multiple post types being queried. At least, that was my assumption.
Can we investigate how this can happen?
#5
@
11 years ago
the Codex indicates that it'll return a string or array, and says multiple could exist: http://codex.wordpress.org/Function_Reference/is_post_type_archive
based on the docs, it's because you can declare one CPT or check for a particular one.
#6
follow-up:
↓ 9
@
11 years ago
is_post_type_archive is only set to true when if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) {
. norcross, you reported this against "trunk" originally. Could anyone actually reproduce this in 3.6? Cause it looks like [25312] broke this. See also #18614 where I suggested a revert.
#9
in reply to:
↑ 6
@
11 years ago
Replying to nacin:
is_post_type_archive is only set to true when
if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) {
. norcross, you reported this against "trunk" originally. Could anyone actually reproduce this in 3.6? Cause it looks like [25312] broke this. See also #18614 where I suggested a revert.
My mistake re: trunk, it should have been 3.6.1
#10
@
11 years ago
Replying to nacin:
is_post_type_archive is only set to true when
if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) {
.
Right, but the code attached to pre_get_posts
(which makes post_type
an array) runs after that, not before.
Replying to nacin:
Could anyone actually reproduce this in 3.6?
I was able to reproduce the post-type-archive-Array
class in both 3.6 and 3.6.1.
Also got a notice from get_post_type_object(), which appears to be fixed in [25312]:
Warning: Illegal offset type in isset or empty in wp-includes/post.php on line 1038
#11
@
11 years ago
Okay, the direction of this fix is proper. But, we should only add one post type as a body class — the rest of post type archives is limited to the first post type listed, as it is specifically designed to not be for multiple post types. That also has the result of not being a major behavior change, while optionally allowing for multiple body classes later.
checking for post_type query_var as an array or single