Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a plug-in which will override the search results returned by Wordpress, with results from a custom XML feed. However, I'm not looking to do this on a separate page, but to replace the results Wordpress would normally display on the blogs search page with the results from my XML feed.

I have been unable to find a filter or hook which would allow me to intercept or override the results wordpress returns, nor can I find one which allows me to override what is displayed on the page. My first thought was to look for something similar to the_content, but I'm unable to locate anything similar to that for use in this situation.

The plug-in is going to be used by sales staff, so the plug-in needs to work in such a way that it requires as little work and technical knowledge as possible on the part of installer. My reasoning for wanting to override the results instead of inserting a new widget is that I want the plug-in to use the same search form the theme uses by default.

Is this even possible? If so, how would I go about doing it?

share|improve this question
    
To be clear. Will you return results from outside of Wordpress? Or just change the search result format to a custom XML feed? –  Steven Aug 18 '11 at 18:34
    
Why would you over-ride the search results instead of just providing an alternative and disabling the default search. –  Wyck Aug 18 '11 at 18:34
    
@Steven The results will be coming from outside Wordpress and replaced with results from an XML feed. The plug-in is only meant to be used by the company I'm developing the plug-in for,and they simply want to populate it with their own search results. –  Wipqozn Aug 18 '11 at 20:47
    
@wyck It's going to be used by sales staff so it needs to be as easy to install as possible, without any manual work required. On the same note I would like for it just use the same search form the theme uses. –  Wipqozn Aug 18 '11 at 20:48

1 Answer 1

up vote 5 down vote accepted

You can use template_include filter hook to check if the current call is a search call and if so include your own template in which you can do what ever you want :

add_filter('template_include','my_custom_search_template');

function my_custom_search_template($template){
    global $wp_query;
    if (!$wp_query->is_search)
        return $template

    return dirname( __FILE__ ) . '/my_search_template.php';

}
share|improve this answer
    
My concern with this is that the plug-in needs to be dropped into any WordPress theme without creating a new template page. I came across this method myself and I believe it would require me to create a template page for the results, or choose a fitting template page. As noted above, the plug-in is going to be used by sales staff so that's not an ideal option. –  Wipqozn Aug 18 '11 at 20:49
    
In that case take a look at the_posts filter hook where you can run the same check if the current query is a search query and if so return your results. –  Bainternet Aug 18 '11 at 21:06
    
I'll take a look at that and report back, thank you :) –  Wipqozn Aug 18 '11 at 21:11
    
The Posts was a good idea, but due to the theme I'm working for with it's not the ideal solution. However I ended up using a slightly different solution then expected, and I template_include was a key component in that. –  Wipqozn Aug 22 '11 at 11:47
    
Are you able to share the solution that you came up with? –  MadtownLems Nov 7 at 20:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.