2

Is it possible, to search just for tags?

Not any other taxonomies or post types, just tag titles.

1 Answer 1

5

Yes its very possible, you just need to create your own search form and processing function form:

<form name="tag-search" method="POST" action="">
  <input type="text" vlaue="" name="tag-q" id="tag-q">
  <input type="submit" name="tag-submit" id="tag-submit" value="Search Tags">
</form>

processing:

<?php
if (isset($_POST['tag-submit']) && $_POST['tag-submit'] == "Search Tags" && isset($_POST['tag-q']) && $_POST['tag-q'] != ""){

    // @todo Sanity check and cleanup $_POST['tag-q'] here.

    $args = array('name__like' => $_POST['tag-q']);
    $tags = get_tags($args);
    $html = '<div class="post_tags_search_r">';
    foreach ($tags as $tag){
        $tag_link = get_tag_link($tag->term_id);

        $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
        $html .= "{$tag->name}</a>";
    }
    $html .= '</div>';
    echo $html;
}
?>

No this is something i have used in the past, the only downside to this is that name__like is case-insensitive so you might want to add the strtolower version to the name__like.

2
  • good hook. But this example in unsafe, we should clean up the [tag-q] to avoid problems Mar 28, 2011 at 21:57
  • @Happy i agree 100%
    – Bainternet
    Mar 28, 2011 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.