Mark McLaren is a Web Analytics Association Member 2007
Mark McLaren is a Web Analytics Association Member

Archive for the "Technical" Category

WordPress Search Form (searchform) Results - Problem Fixed!

If you use WordPress, you may have discovered a problem with search results on your website or blog: a search using the search form (a.k.a. searchform) on an internal page generates either no result (the page does not change) or a “Page not found” 404 error. Fortunately, I can no longer demonstrate the problem for you on this website, because I found and corrected the faulty PHP source code.

Here’s what you will find if you are experiencing the problem: when you or someone else submits a query using the WordPress searchform, that is, you type something into the Search box on your website or blog and click the ‘Go’ button, you see no change in the page or you see a “Page not found” page, and in the web browser’s address window you will find a URL that looks similar to this:

http://www.mcbuzz.com/web-marketing-blog/
about-web-marketing-pro-blog/?s=[search term]&sbutt=Go

The URL shows the page that the search was done from:

http://www.mcbuzz.com/…/about-web-marketing-pro-blog/

which is why it doesn’t work.

The solution is simple. The URL should be:

http://www.mcbuzz.com/web-marketing-blog/?s=[search term]&sbutt=Go

with no specific page in it, just the home page. (On the Web Marketing Pro Blog, the home page is http://www.mcbuzz.com/web-marketing-blog/.)

In your WordPress theme source files, the search <form> tag contains an action attribute that is empty, so it looks like this:

<form id=”searchform” method=”get” action=”">

The searchform is usually in a theme’s sidebar.php file. Sometimes it is in the header.php file.

You need to insert a bit of code into the action attribute. Using a text editor like NotePad or WordPad, change the action attribute so it looks like this:

<form id=”searchform” method=”get” action=”<?php bloginfo(’url’); ?>/”>

Watch out for the two “>” brackets at the end. You need all of

<?php bloginfo(’url’); ?>/

between the action= quote marks.

Make that change, and your search results will be good to Go!

Popularity: 92% [?]

Search this site:

Font Size

Technorati Bling

iStockphoto.com stock photography link

Click here to check out
The Seattle PHP Meetup Group!