I’m creating my own form based on this and I’d like to have a tag selector which is similar to the one on StackExchange. I can roll my own but I was wondering if something similar already exists.

Thanks!

2 Answers
2

you can do that using JQuery autocomplete plugin

and once you have included all of the needed JS files just add this code after your new post form

$terms = get_terms("post_tag");
$tags="";
$count = count($terms);
 if ( $count > 0 ){ 
     foreach ( $terms as $term ) {
       $tags .=  '"'.$term->name.'", '; 
    }
    $tags = substr($tags,0,-2);
 }

echo ' <script>
JQuery("#post_tags").autocomplete(['.$tags.'], {
        width: 320,
        max: 4,
        highlight: true,
        multiple: true,
        multipleSeparator: ", ",
        scroll: true,
        scrollHeight: 300
    });
</script>';

note: Now this is good if you only have a small number of tags, but if you have hundreds or thousands of tags then using an ajax solution is a must.

Leave a Reply

Your email address will not be published. Required fields are marked *