0

I recently bought a directory theme. It uses a page created search template that is found at templates/template-search-results.php. So what I am trying to do, is to output search results in my posttype-archive.php template, which I think is how it should be by default. How do I achieve this?

So far I've tried to add rewrite_rules along with Query_vars for SEO search URLs. I added this in the functions.php:

function add_query_vars( $query_vars ) {
    $new_vars = array( 'vehicle-type', 'fuel', 'color', 'status', 'gearbox', 'interior', 'exterior', 'safety', 'extra', 'location', 'vehicle-year', 'model' );

    return array_merge( $new_vars, $query_vars );
}
add_filter( 'query_vars', 'add_query_vars' );


function add_rewrite_rules() {
    global $wp_rewrite;

    $new_rules = array( 'vehicles/vehicle_status/(.+?)/vehicle_fuel_type/(.+?)/vehicle_color/(.+?)/vehicle_status/(.+?)/vehicle_gearbox/(.+?)/vehicle_interior_feature/(.+?)/vehicle_exterior_feature/(.+?)/vehicle_safety_feature/(.+?)/vehicle_extra/(.+?)/vehicle_location/(.+?)/vehicle_year/(.+?)/vehicle_model/(.+?)/?$' => 'index.php?post_type=vehicles&vehicle_status=' . $wp_rewrite->preg_index(1) . '&vehicle_fuel_type=' . $wp_rewrite->preg_index(2) . '&vehicle_color=' . $wp_rewrite->preg_index(3) . '&vehicle_status=' . $wp_rewrite->preg_index(4) . '&vehicle_gearbox=' . $wp_rewrite->preg_index(5) . '&vehicle_interior_feature=' . $wp_rewrite->preg_index(6) . '&vehicle_exterior_feature=' . $wp_rewrite->preg_index(7) . '&vehicle_safety_feature=' . $wp_rewrite->preg_index(8) .'&vehicle_extra=' . $wp_rewrite->preg_index(9) .'&vehicle_location=' . $wp_rewrite->preg_index(10) . '&vehicle_year=' . $wp_rewrite->preg_index(11) . '&vehicle_model=' . $wp_rewrite->preg_index(12)' ) ;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');'
  • What you tried so far? – prosti Dec 6 '16 at 22:18
  • @prosti so far I've added rewrite_rules along with query_vars but still no luck. please see above. I've added code – joe city Dec 12 '16 at 23:40
  • have you tried to flush the rules? – prosti Dec 13 '16 at 10:14
  • @prosti yes, I always flush the rules after making changes, but still. – joe city Dec 14 '16 at 12:40
  • how do you flush your rules? – prosti Dec 14 '16 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.