By all rights it should work, here’s the same thing applied to my own site:
tomjn.com/?s=talk&post_type=tomjn_talks vs tomjn.com/?s=talk . Something else is the problem
Specifically, if you replace the main query with a query_posts
call or a WP_Query
, that query won’t take into account parameters passed via the URL unless explicitly passed through manually.
Instead, use the pre_get_posts
filter to modify the main query, rather than creating a new query to replace it.This ensures any additional queries passed via the URL will also work, and reduces time spent querying the database significantly for a nice performance boost.
Additionally, if you already use pre_get_posts
, setting the post_type
will override the URL parameter, so you need to check for its existence