I am creating a custom rewrite rule so I can implement a postcode search of a CPT. I have manged to insert a custom template but it outputs in the Head currently. I tried including a new base-custom.php but it just loads base.php. Do I need to filter SageWrapping somehow?
class Experts {
public function __construct() {
add_action( 'init', array( $this, 'expert_routes' ) );
add_filter( 'query_vars', array( $this, 'manage_expert_routes_query_vars') );
add_action( 'template_redirect', array( $this, 'front_controller' ) );
add_action( 'before_expert_postcode_search', array( $this, 'expert_postcode_search_results' ) );
}
public function expert_routes() {
add_rewrite_rule( '^expert/([^/]+)/?', 'index.php?control_action=$matches[1]', 'top' );
}
public function manage_expert_routes_query_vars( $query_vars ) {
$query_vars[] = 'control_action';
return $query_vars;
}
public function front_controller() {
global $wp_query;
$control_action = isset ( $wp_query->query_vars['control_action'] ) ? $wp_query->query_vars['control_action'] : '';
switch ( $control_action ) {
case 'search':
do_action( 'before_expert_postcode_search' );
break;
}
}
public function expert_postcode_search_results(){
get_template_part('templates/content-experts-search'); // Loads in HEAD
//include('base-template-expert-search.php'); // Just loads base.php
}
}