WordPress.org

Ready to get started?Download WordPress

Forums

Auto suggest tags for form field on main page (2 posts)

  1. wilcosky
    Member
    Posted 2 years ago #

    Hi,

    WordPress has javascript built in called suggest.js. If anyone has experience with it, please help...

    I have a form field on my main page. I simply want my members to see tag suggestions while they type. The following thread, which is the only thread I can find on this topic, isn't quite helping me.
    http://wordpress.org/support/topic/how-to-add-autocomplete-autosuggest-to-text-input-field

    That thread points to a website which has a quick tutorial on how to implement tag suggestions for the admin section. However, I need to do this in the front end of my site. I tried using the code on that page and was unsuccessful.

    I assume javascript needs to be added to my header, then possibly something added to the form field code.

  2. wilcosky
    Member
    Posted 2 years ago #

    I figured this out so I'm leaving the solution here for anyone in the future that wants to add tag suggestions to any input field on their WordPress site.

    This guy actually posted the solution on his site in '07, but what he posted is more for the admin area.

    http://sudarmuthu.com/blog/using-wordpress-built-in-tag-auto-complete-script-in-your-plugins

    All I had to do was include some Javascript and insert the id of my tag field. It ended up being very simple... I was trying to make it way too complicated.

    First, have your site call the suggest.js that now comes with every WordPress site. It's in your js/jquery folder I believe. Once you include the suggest.js, then you add the Javascript below which tells your site which text box you're adding auto suggest to, and that's it.

    <script type="text/javascript">
            jQuery('#YOURINPUTBOXIDHERE').suggest("<?php echo get_bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=post_tag", {multiple:true, multipleSep: ","});
     </script>

Topic Closed

This topic has been closed to new replies.

About this Topic