kaniosrn-j
11/21/2017 - 4:25 PM

WordPress - Search for Tag and Title

	<?php 
		$paged = (get_query_var('paged')) ? get_query_var('paged'): 1; 

				$set1 = array(
					'fields'=> 'ids',
					'post_type' => $post_type,
					'tag' => $_REQUEST[ 'search' ]
				);
				$set1_results = new WP_Query( $set1 );
				
				$set2 = array(
					'fields'			=> 'ids',
					'post_type'        => $post_type,
					'suppress_filters' => false, // important!
					's'                => $_REQUEST[ 'search' ]				
				);
				$set2_results = new WP_Query( $set2);

				 $combined_ids = array_merge($set1_results->posts, $set2_results->posts);
				 $combined_ids = array_unique($combined_ids);
				
				 $combines_sets = new WP_Query(
					 array(
						'post_type'        => $post_type,
						'posts_per_page'   => 6,
						'paged'            => $paged,
						'post_status'      => 'publish',
						'post__in' => $combined_ids
					 )
				 );
				 ?>
				 	<!-- Search Form -->
				<form method="get" id="searchform" action="<?php echo esc_url( get_permalink( get_page_by_title( 'Page_Template' ) ) )?>">
					<input type="text" class="field" name="search" id="search" placeholder="Search by keyword..." />
					<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />
				</form>