I am working on a WordPress site that has several custom post types. Of course this lends itself to writing a custom search form. However, the results from test searches have been less than understandable.
Let me paint a picture of the posts that are being searched.
- Post Type: A, Keywords: apple, bed, all
- Post Type: A, Keywords: apple, cat, all
- Post Type: B, Keywords: cat, dog, all
- Post Type: B, Keywords: dog, egg, all
- Post Type: C, Keywords: apple, egg, all
Post Types A, B, and C have
'exclude_from_search' => false and
'publicly_queryable' => true.
Based on https://codex.wordpress.org/WordPress_Query_Vars I would expect that I could use
post_type in the search query string to define the post type. However, when I do so the results are not what I would expect.
?s=appleresults in 1 and 2. It should be 1, 2 and 5.
?s=apple&post_type=Aresults in 1 and 2. This is correct.
?s=apple&post_type=Bresults in 1 and 2. It should be none.
?s=apple&post_type=Cresults in 1 and 2. It should be 5.
?s=dogresults in 3 and 4. This is correct.
?s=dog&post_type=Aresults in 3 and 4. It should be none.
?s=dog&post_type=Bresults in 3 and 4. This is correct.
?s=dog&post_type=Cresults in 3 and 4. It should be none.
?s=allresults in 1, 2, 3, and 4. It should be 1, 2, 3, 4, and 5.
?s=all&post_type=Cresults in 1, 2, 3, and 4. It should be 5.
post_typedo anything when included in the URL?
- Why does 5 never show up in the results? In fact no C post types are shown in search results.
- Is this part of WordPress just fundamentally broken, and I should use a
pre_get_postshook to modify the query?