I have form where I list all terms associated with posts as check boxes, user should pick few of them, hit search and get all posts that match all chosen terms. It works great when there are posts that match search criteria. My question is how do I display posts that have just few of matched terms and how to sort results based on number of matches. Any help is much appreciated. Thanx.
So this is the form inside search page:
<form action="<?php bloginfo('template_url') ?>/build_search.php" method="post" accept-charset="utf-8">
<?php $terms = get_terms( 'my_tax' );
$checkboxes = '';
foreach($terms as $term) :
$checkboxes .='<input type="checkbox" name="term[]" value="'.$term -> slug.'" id="term-'.$term->term_id.'" /><label for="term-'.$term->term_id.'">'.$term->name.'</label>';
endforeach;
print $checkboxes;
?>
<input id="submit" type="submit" value="Search">
This is what I put in build_search.php file
if (isset($_POST["term"])){ $terms_array = array(); $terms_array = $_POST["term"]; foreach ($terms_array as $key => $value) { $string .= $value.'+'; } $terms_string = substr($string, 0, -1); $term = $terms_string; } else { $term = ""; } $url = header("Location:/?my_tax=$term");
after that I have only taxonomy-my_tax.php with regular loop in it.
Well the only way i can think of is to create an two dimentions array of the results you want to output, and the number of matching tags.
so for example:
this is untested so try and report back.