SearchWP Supplemental Engines with main loop

functions.php

/** * SearchWP Query * */ function ea_searchwp_query() { if( empty( $_GET['swpquery'] ) ) return; $args = array( 's' => esc_attr( $_GET['swpquery'] ), 'engine' => esc_attr( $_GET['swpengine'] ), 'page' => get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1, ); $tax_query = ea_get_tax_query(); if( !empty( $tax_query ) ) $args['tax_query'] = $tax_query; $loop = new SWP_Query( $args ); global $wp_query; $wp_query->max_num_pages = $loop->max_num_pages; // for pagination $wp_query->posts = $loop->posts; // for loop } add_action( 'tha_content_loop', 'ea_searchwp_query', 9 ); add_action( 'tha_content_loop', 'wp_reset_query', 11 );

searchform.php

<?php /** * EA Starter * * @package EAStarter * @since 1.0.0 * @copyright Copyright (c) 2014, Contributors to EA Genesis Child project * @license GPL-2.0+ */ global $ea_search_settings; $args = wp_parse_args( $ea_search_settings, array( 'action' => home_url( '/' ), 'engine' => false, )); $s_name = !empty( $args['engine'] ) ? 'swpquery' : 's'; $value = !empty( $_GET[$s_name] ) ? esc_html( $_GET[$s_name] ) : false; ?> <form role="search" method="get" class="search-form" action="<?php echo esc_url( $args['action'] ); ?>"> <label> <span class="screen-reader-text">Search for</span> <input type="search" class="search-field" placeholder="Enter search terms…" value="<?php echo $value; ?>" name="<?php echo $s_name;?>" title="Search for" /> <input type="hidden" name="swpengine" value="<?php echo $args['engine'];?>" /> </label> <button type="submit" class="search-submit"><i class="icon-search"></i></button> </form>

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk