Query with no terms uses index.php template instead of archive.php

I’m using the Query Multiple Taxonomies plugin to get a page of search results (all of which are a custom post type – car).
If any search terms are added, so the url looks like this:

http://mysite.com/car/?makemodel=ford&body=&gearbox=&fuel=&minprice=&maxprice=

then the archive.php template is used. However, if the user clicks search without adding any terms, so the url looks like this:

Read More
http://mysite.com/car/?makemodel=&body=&gearbox=&fuel=&minprice=&maxprice=

then index.php is used instead. I’d like to ensure this ’empty’ search uses the archive.php template too.

These bits from my functions file may be relevant:

// Ensure Custom Post Type is included in query

add_action( 'pre_get_posts', 'add_my_post_types_to_query' );

function add_my_post_types_to_query( $query ) {
    if ( is_home() && $query->is_main_query() )
        $query->set( 'post_type', array('car' ) );
    return $query;
}


// Tweaks to taxonomy layered search

function my_qmt_base_url( $base ) {
    return get_bloginfo('home').'/car/';
}
add_filter( 'qmt_base_url', 'my_qmt_base_url' );


function my_qmt_reset_url( $reset_url ) {
    $url = get_permalink();
    return $url;

}
add_filter( 'qmt_reset_url', 'my_qmt_reset_url' );

Any help would be much appreciated!

Graham

Related posts

Leave a Reply

1 comment

  1. You could filter template_include:

    add_filter( 'template_include', 'wpse_97347_force_archive' );
    
    function wpse_97347_force_archive( $template )
    {
        if ( isset ( $_GET['makemodel'] ) && empty ( $_GET['makemodel'] ) )
            return get_archive_template();
    
        return $template;
    }
    

    Not tested.