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 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:

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

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
Wow, thanks for the speedy reply! Works first time! –  Grahamd Apr 26 '13 at 14:19
add comment

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.