Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter juliston

    (@juliston)

    function bsearch_template_redirect($template) {
    	// not a search page; don't do anything and return
    	if ( ( stripos( $_SERVER['REQUEST_URI'], '?s=' ) === false ) && ( stripos( $_SERVER['REQUEST_URI'], '/search/' ) === false ) && ( ! is_search() ) ) {
    		return $template;
    	}
    
    	global $wp_query, $bsearch_settings;
    
    	// If seamless integration mode is activated; return
    	if ( $bsearch_settings['seamless'] ) {
    	    return $template;
    	}
    
    	// if we have a 404 status
    	if ( $wp_query->is_404 ) {
    		// set status of 404 to false
    		$wp_query->is_404 = false;
    		$wp_query->is_archive = true;
    	}
    
    		// change status code to 200 OK since /search/ returns status code 404
    	@header( 'HTTP/1.1 200 OK', 1 );
    	@header( 'Status: 200 OK', 1 );
    
    	$search_query = get_bsearch_query();
    
    	$limit = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : $bsearch_settings['limit']; // Read from GET variable
    
    		// Added necessary code to the head
    	add_action( 'wp_head', 'bsearch_head' );
    
    		// Set thw title
    	add_filter( 'wp_title', 'bsearch_title' );
    
    	// If there is a template file within the parent or child theme then we use it
    	$priority_template_lookup = array(
    		get_stylesheet_directory() . '/better-search-template.php',
    		get_template_directory() . '/better-search-template.php',
    		plugin_dir_path( dirname( __FILE__ ) ) . 'templates/template.php',
    	);
    
    	foreach ( $priority_template_lookup as $exists ) {
    
    		if ( file_exists( $exists ) ) {
    
    			return $exists;
    			//include_once( $exists );
    			//exit;
    
    		}
    	}
    
    	return $template;
    }
    add_action( 'template_include', 'bsearch_template_redirect', 1 );
Viewing 1 replies (of 1 total)