Closed michaelsauter closed 11 years ago
is there a significance of -1 vs 0? my tests pass using -1.
They shouldn't pass. I actually created this pull request without knowing what -1 really does, I just figured it was wrong. I now checked the Wordpress code, and it basically transforms -1 to 1, so you'll get the post with ID 1 (if you've got one) in case there are no search results.
See wp-includes/query.php, line 2159. It uses absint(http://codex.wordpress.org/Function_Reference/absint) for all values in post__in.
If you 0 instead, it should be safe.
of course it does! thanks for finding, will write a test to reproduce and pull this in
When no result is found,
$wp_query->query_vars['post__in']
should be set toarray(0)
. Currently, if no result is found, WordPress will load one post.By the way, I fixed this in both search.php and category.php, but there is lots of duplication between those two files so you might want to extract the common functionality.