How to replace the default search query parameter in WordPress

Add the following code to your functions.php to replace the default WordPress search parameter (i.e., …pagename/?s=search_phrase…).

// Add this code to your functions.php file in your active theme folder
  1.  
  2. // Allow WordPress to access "search" in the query string
  3. function ds_whitelist_new_search_parameter( $allowed_query_vars ) {
  4.  $allowed_query_vars[] = 'search';
  5.  return $allowed_query_vars;
  6. }
  7. add_filter('query_vars', 'ds_whitelist_new_search_parameter' );
  8.  
  9.  
  10. // populate s parameter with value of search
  11. function ds_swap_search_parameter($query_string) {
  12.  
  13.  $query_string_array = array();
  14.  
  15.  // convert the query string to an array
  16.  parse_str($query_string, $query_string_array);
  17.  
  18.  // if "search" is in the query string
  19.  if(isset($query_string_array['search'])){
  20.   $query_string_array['s'] = $query_string_array['search']; // replace "s" with value of "search"
  21.   unset($query_string_array['search']); // delete "search" from query string
  22.  }
  23.  
  24.  return http_build_query($query_string_array, '', '&'); // Return our modified query variables
  25. }
  26. add_filter('query_string', 'ds_swap_search_parameter');

My example uses “search”. So instead of example.com/?s=search+phrase my site uses example.com/?search=search+phrase (both are recognized).

This is handy if you have another snippet on your page that also wants to use the ‘s’ parameter (like the embed code from sharefile.com). To replace other WordPress query vars (like p or order) replace ‘s’ in $query_string_array['s'] (near line 21) with the query var you’d like to replace (see http://codex.wordpress.org/WordPress_Query_Vars for a partial list of query variables). Just make sure the new query variable name doesn’t conflict with any of the built-in ones.

Once you’ve added this code, you’ll also need to update any search forms you have with the new variable name (in your theme directory searchform.php).

“The name server is not sufficient or hasn’t been approved.”

We recently came across this error message while trying to point domains in the 1&1 Control Panel to our new VPS. Calling tech support was of course pointless (the rep kept trying to tell me it was a temporary glitch). After some Googling and messing around, I discovered the fix:

1. Add your name server domain as an external domain. For example, if your new name server is ns1.mydomain.com, add mydomain.com as an external domain. Ignore any suggestions to change mydomain.com‘s name servers.
2. Create sub-domains for that new external domain matching your name server. Using the example above, ns1.mydomain.com, ns2.mydomain.com
3. You can now use ns1.mydomain.com and ns2.mydomain.com for nameservers for any domain in your 1&1 account.

Note: This should be obvious, but also make sure the subdomain works. If it’s a brand new domain, it may take a day or two for 1&1 to be able to resolve the domain.

Review of Lethbridge By-Election Candidate Websites

With just a few weeks left in the by-election for Alderman in Lethbridge, I thought it might be interesting to take a look at the websites of the 10 declared candidates to look at how they compare, what they’re doing right and what could be improved. Campaign websites are critical tools in most elections these days and can have a significant impact on success of candidate.

Continue reading »

Getting Started with Google AdWords

So you have a brand new website, but no traffic. What can you do? One way to start getting visitors right away is to invest in some advertising. When it comes to online advertising, you have a lot of options, but the big dog is definitely Google AdWords.

What is Google AdWords?

AdWords are the “sponsored” links that show up in Google when you do a search. They are almost always related to your search phrase. These are paid ads are usually sponsored by the sites in the links.

Continue reading »

WordPress 3.0 Released

We’re big fans of WordPress so today is a big day for us. After many months of hard word, the WordPress team released version 3.0 today of the open source CMS, code-named “Thelonious”.

Continue reading »

Page 1 of 512345