Overwriting WordPress' search function
-
Hi all, I’ve been working on trying to build a simple plugin that will replace the existing WordPress search feature with the mySQL full text search.
My objectives are to develop a plugin that is generic, and theme friendly. I don’t want to put all sorts of hacks in themes to make it work. So the idea is to utilize the search box already in WordPress, but instead of passing that query to WordPress, I want to intercept it, do something with it, and then pump the new HTML code back to WordPress, so the idea (as can be seen below) works to some degree, where I’m trying to intercept the search, force it to a page, and then rewrite the page output through another plugin.
I think I may have the wrong hooks, or the wrong filters, or something, so I’d like to ask for some advice from the group..
function alter_the_query( $request ) { $query = new WP_Query(); $query->parse_query( $request ); if($query->is_search()) { // so if this is a search, force it to a single page $request['p'] = '6'; // disable the current search page $query->is_search = false; // now we'll overwrite the output, and in this hook we will do the actual searching and render the search output. add_filter('the_content','fts_search_results'); } return $request; } add_filter( 'request', 'alter_the_query' );
The topic ‘Overwriting WordPress' search function’ is closed to new replies.