Search results not displaying for multiple word search in WordPress

与世无争的帅哥 提交于 2019-12-23 10:38:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!