Opened 4 years ago
Last modified 4 years ago
#50885 new defect (bug)
Setting a pre_get_posts query post_type to array results in broken wp-admin filters
Reported by: | matpratta | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.4.2 |
Component: | Query | Keywords: | |
Focuses: | administration | Cc: |
Description
I have a in-house plugin which creates a few extra alternate post types (eg. post_custom
), and one of its requirements is that these post types are queried together with normal posts.
To do this, I've implemented a function which converts any queries for the post
post type into array( 'post', 'post_custom', ... )
and it works as it should, but when on wp-admin, if one tries to go into the default "Posts" menu and filter by author or even search for anything, it will return a message saying "Invalid post type".
Checking the URL, it will contain the post_type
query string as "Array" instead of "post", and changing it manually to "post" fixes the issue. I guess the wp-admin interface is not handling the array of post types correctly?
Hi there, welcome back to WordPress Trac! Thanks for the report.
Just noting that it's generally recommended to include
! is_admin() && $query->is_main_query()
checks when usingpre_get_posts
, so that the correct queries are altered. See Targeting the right query.