parisholley / wordpress-fantastic-elasticsearch

Improve wordpress search performance/accuracy and enable faceted search by leveraging an ElasticSearch server.
MIT License
162 stars 64 forks source link

Use 0 for post__in when no results are found #30

Closed michaelsauter closed 11 years ago

michaelsauter commented 11 years ago

When no result is found, $wp_query->query_vars['post__in'] should be set to array(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.

parisholley commented 11 years ago

is there a significance of -1 vs 0? my tests pass using -1.

michaelsauter commented 11 years ago

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.

parisholley commented 11 years ago

of course it does! thanks for finding, will write a test to reproduce and pull this in