Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Allow visitors to search by multiple tags (specific IDs) WordPress

  • REFUNDED

I'm trying to create a search form/filter that allows visitors to search by specific tags.

I've implemented this solution:


<form method="get" action="<?php bloginfo('url'); ?>">
<fieldset>
<input type="text" name="s" value="" placeholder="search…" maxlength="50" required="required" />
<p>Refine search to posts containing chosen tags:</p>
<?php
// generate list of tags
$tags = get_tags();
foreach ($tags as $tag) {
echo
'<label>',
'<input type="checkbox" name="taglist[]" value="', $tag->slug, '" /> ',
$tag->name,
"</label>\n";
}
?>
<button type="submit">Search</button>
</fieldset>
</form>


And this in functions.php:


// advanced search functionality
function advanced_search_query($query) {

if($query->is_search()) {

// tag search
if (isset($_GET['taglist']) && is_array($_GET['taglist'])) {
$query->set('tag_slug__and', $_GET['taglist']);
}

return $query;
}

}
add_action('pre_get_posts', 'advanced_search_query', 1000);


But it displays ALL tags. How would I get specific tags by ID for visitors to select?

Answers (1)

2015-08-21

Balanean Corneliu answers:

Hy man i see you need more specific settings for that search. Why you dont buy a premium search with easy customization from wp-admin without coding.
[[LINK href="http://codecanyon.net/item/ajax-search-pro-for-wordpress-live-search-plugin/3357410"]]Try Ajax Search Pro[[/LINK]]


drinkguesser comments:

Hi Balanean,

Because I only want to show specific tags for specific pages.

We have a travel company so on our lodging pages we would only want them to be able to select something like:

- Cabins
- Hotels
- Condos

and/or

- 1 star
- 2 star
- 3 star

You can see at the bottom of this page, what I currently have and that I'm trying to fix: http://traveloffice.org/1-bedroom-cabins-branson/