问题
I've customized a theme and am having some problems with search results using multiple-word queries. Site is live at www.abetterworldbydesign.com
Searching for a single word works as expected.
Searching for multiple words that should have returned results shows blank results.
Code for searchform.php below.
<form id="searchform" name="searchform" method="get" action="<?php echo home_url(); ?>">
<div>
<input type="text" id="s" name="s" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'richwp' ); ?>" />
</div>
</form>
My code in search.php for initializing WP_Query follows exactly the code listed in the codex. Full code for search.php on pastebin.
回答1:
I would guess you need to decode the search term you are extracting from the query string, like so: $search_query[$query_split[0]] = urldecode($query_split[1])
. Although, you could probably just use Wordpress's get_query_var function instead of all that code.
回答2:
Line 16 of your search PHP
$query_args = explode("&", $query_string);
Try changing to this
$query_args = explode(" ", $query_string)
来源:https://stackoverflow.com/questions/6819226/search-results-not-displaying-for-multiple-word-search-in-wordpress