WP Custom Fields Search is a great plugin but I’ve a problem regarding the plugin returning results using the homepage.

When I click the submit button, results are shown on the homepage instead of the search.php page!

Searching on the web, I’ve read that the plugin should output search results on the search page template or, if search.php is missing, on the homepage.

My theme has search.php but the plugin is not using it: I need to force the plugin to output search results in the search results page.

Looked at the plugin’s code and quite sure that some code should be changed in the “extra_search_fields.php” file but I’m not sure where and how to force the results to output on the search template instead of the homepage.
Guess that at about line 230 is where to hack the code:

function renderWidget($params=array(),$p2 = array()){
    $title = $this->getTitle($params);
    $inputs = $this->getInputs($params);
    $hidden = "<input type="hidden" name="search-class" value="".$this->getPostIdentifier().""/><input type="hidden" name="widget_number" value="".$p2["number']."'/>";
    $formCssClass="custom_search widget custom_search_".$this->nameAsId();
    $formAction = get_option('home');
    if(function_exists('locate_template'))
        $formTemplate = locate_template(array('wp-custom-fields-search-form.php'));
    if(!$formTemplate) $formTemplate = dirname(__FILE__).'/templates/wp-custom-fields-search-form.php';

    foreach($inputs as $k=>$v){
        if($v->isHidden()){
            $hidden.=$v->getInput(false);
            unset($inputs[$k]);
        }
    }
    include($formTemplate);
}

function isPosted(){
    return $_GET['search-class'] == $this->getPostIdentifier();
}
function getPostIdentifier(){
    return get_class($this).'-'.$this->id;
}
function isHome($isHome){
    return $isHome && !$this->isPosted();
}
function rewriteHome($homeTemplate){
    if($this->isPosted()) return get_query_template('search');
    return $homeTemplate;
}

Can someone please help me?

1 Answer
1

Instead of $formAction = get_option('home'); use $formAction = get_template_part( 'search' );

Leave a Reply

Your email address will not be published. Required fields are marked *