1

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

1 Answer 1

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.

1
  • Wow, thanks for the speedy reply! Works first time!
    – Grahamd
    Commented Apr 26, 2013 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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