[wp-trac] [WordPress Trac] #11330: Empty search takes you to hompage, even when homepage is not your blog
WordPress Trac
wp-trac at lists.automattic.com
Fri Dec 4 21:57:23 UTC 2009
#11330: Empty search takes you to hompage, even when homepage is not your blog
--------------------------+-------------------------------------------------
Reporter: jacobfogg | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Unassigned
Component: General | Version: 2.8.5
Severity: normal | Keywords:
--------------------------+-------------------------------------------------
1. In the admin tool, if you go to "Settings->Reading" then choose "A
static page (select below)" and choose a page for your "Front page" and a
different page for your "Posts page".
2. Visit your blog (http://localhost/ in my case) and you will see your
static page.
3. Navigate to your blog (http://localhost/blog/ in my case).
4. Enter a search string (e.g. "test") and click "Search". This will take
you to the search results page (http://localhost/?s=test in my case).
Notice that it is located at the base of your site.
5. Return to your blog, leave the search textbox blank and click "Search".
This _should_ take you to the search results page but takes you to the
_Homepage_ instead (http://localhost/?s= in may case).
IMHO, a blank search string _should_ take you to the search page and state
"No posts found. Try a different search?" as it does when you enter an
invalid search. At the very least, it should take you to the blog page.
The reason it takes you to the homepage is due to how the
get_search_form() function in the /wp-includes/general-template.php file
creates the Action url for the search form:
{{{
$form = '<form role="search" method="get" id="searchform" action="' .
get_option('home') . '" >'
}}}
I propose a change in the code that will do the following:
{{{
if(get_option('show_on_front') == 'page'){//if the blog is not the front
page
$searchAction = get_page_link(get_option('page_for_posts'));//get
the link to the blog
}else{//if it is the front page
$searchAction = get_option('home')."/";//get the link to the home
}
$form = '<form role="search" method="get" id="searchform" action="' .
$searchAction . '" >
}}}
That way, at the very least, you know the search is landing where it
belongs.
This, however, does not _fix_ the issue where a blank search does not land
you on the search page. My guess is, wherever it is determined what page
is displayed, there is a check for something like:
{{{
if($_REQUEST['s']!=''){
//if the request var 's' is not blank, this is a search
}
}}}
If that is indeed the case, a simple change of the code to something like
this should do the trick:
{{{
if(isset($_REQUEST['s'])){
//if the request var 's' isset, this is a search
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/11330>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list