Site icon Hip-Hop Website Design and Development

Search by tag, category and author without plugin

I’m creating a website that has search feature. I am wondering what should i do in order to make the search box works like search everything. The search term that visitor inserted may be hitting the tag name of the post, category of the post, content inside post or title of the post. As long as there is a word within the post hit by search term, the result will show. I’m not going to use plugin, or to add radio button to my search form. I tried to search around but failed. Any suggestion and solution?

<!DOCTYPE html>
<html>
<?php get_header(); ?>
<body>

<?php $q1 = get_posts(array(
    'post_status' => 'publish',
    'posts_per_page' => '5',
    's' => get_search_query()
    )
);

$q2 = get_posts(array(
    'post_status' => 'publish',
    'posts_per_page' => '5',
    'tax_query' => array(
            //your query
        )
    )
);

$merged = array_merge($q1, $q2);

?>

<?php echo wp_specialchars($s); ?><br/>
<?php the_search_query(); ?><br/>
<?php the_search_query(); ?>
<br/>
<article>
<p>You have searched for "<?php echo wp_specialchars($s); ?>". We found <?php /* Search Count */ 
    $allsearch = &new WP_Query("s=$s&showposts=-1"); 
    $key = wp_specialchars($s, 1); 
    $count = $allsearch->post_count; 
    $text  = '<span class="resultsFounds">';
if ( $allsearch->found_posts <= 0 ) {
    $text .= sprintf(__( 'no company' ), $count );
}

elseif ( $allsearch->found_posts <= 1 ) {
    $text .= sprintf(__( '%d related company' ), $count );
} 

else {
    $text .= sprintf(__( '%d related companies' ), $count );
}       
$text .= '</span>'; 
echo $text;
?> with the keyword you searched for. If the results are not what you expected, we suggest you to try for different keywords which related to the company.</p>
<?php if (have_posts()) : ?>
<h2>Keywords : <?php echo wp_specialchars($s); ?><?php 
    /* Search Count */
    $count = $wp_query->found_posts; 
    $text  = '<span class="resultsFound">';
if ( $count  <= 0 ) {
    $text .= sprintf(__( '( no company )' ), $count );
}

elseif ( $count <= 1 ) {
    $text .= sprintf(__( '( %d company )' ), $count );
} 

else {
    $text .= sprintf(__( '( %d companies )' ), $count );
}       
$text .= '</span>'; 
echo $text;
?></h2>

<?php include("adsRandom.php"); ?>
<?php include("boostBiz/bizAds.php"); ?>

<?php while (have_posts()) : the_post(); ?>
<div class="ncc <?php the_ID(); ?><?php if( date('U') - get_the_time('U', $post->ID) < 24*60*60 ) : ?> new<?php endif; ?><?php if (is_sticky()) { ?> sponsored<?php } ?>" <?php if (is_sticky()) { ?>title="Our Advertiser"<?php } ?>>
<h3 class="excerpt"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php search_title_highlight(); ?></a></h3>
<?php search_excerpt_highlight(); ?>
<p class="excerptInfo"><?php printf( __( 'Listed in %2$s', 'NCC' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?> |<?php
$tags_list = get_the_tag_list( '', ', ' );
if ( $tags_list );
?>
<?php printf( __( ' Located In: %2$s', 'NCC' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?><?php if( date('U') - get_the_time('U', $post->ID) < 24*60*60 ) : ?> | Published <?php echo get_the_date(); ?><?php endif; ?></p>
</div><!--ncc <?php the_ID(); ?>-->

<?php endwhile; ?>
<?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?>

<?php else : ?>

<h2><?php _e('Keywords : ','NCC'); ?><?php echo wp_specialchars($s); ?><?php /* Search Count */ 
    $allsearch = &new WP_Query("s=$s&showposts=-1"); 
    $key = wp_specialchars($s, 1); 
    $count = $allsearch->post_count; 
    $text  = '<span class="resultsFound">';
if ( $allsearch->found_posts <= 0 ) {
    $text .= sprintf(__( '( Nothing Found )' ), $count );
}

elseif ( $allsearch->found_posts <= 1 ) {
    $text .= sprintf(__( '( We found %d company )' ), $count );
} 

else {
    $text .= sprintf(__( '( We found %d companies )' ), $count );
}       
$text .= '</span>'; 
echo $text;
?></h2>

<article class="nccSingle">
<p>Your search - "<b><?php echo wp_specialchars($s); ?></b>" - did not match any documents. Possibly, there is no company listed with this keyword. Or, the inserted keyword was wrong in spelling?</p>
<p><b>Suggestions:</b></p>
<ul>
  <li>Make sure all words are spelled correctly.</li>
  <li>Try different keywords.</li>
  <li>Try more general keywords.</li>
</ul>
</article>
<?php endif; ?>
</body>
</html>