Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a simple frontend form to allow users to submit posts - similar to the tutorial here - http://voodoopress.com/ . I also have a couple of custom taxonomies which i have as text input boxes on my form. This is all working but i was wondering if there is anyway i can have all the fields including Post Title and the taxonomies to auto suggest existing values?

thanks

share|improve this question
    
How do you mean to auto-suggest? As in, if someone starts creating a new post, you query for similar post titles and recommend those? –  m0r7if3r Feb 6 '12 at 16:34
    
yes that is correct. Also similar for my other text boxes. eg i have an artist field which i would like to pull terms from my Artists taxonomy when a user starts typing –  coolGeek Feb 6 '12 at 17:22
add comment

2 Answers

up vote 1 down vote accepted

Ok not sure if this is the best method to use but it worked for me. I used a combition of jquery-ui-autocomplete - and the JSON API plugin

First download the required js files from the link above. I used jqueri-ui from the Google library Install and activate JSON API plugin

I then used the following javascript to auto suggest when typing into the "title" input field on my custom post form

<script type="text/javascript">
$(function() {
        $('#title').autocomplete({
        source: function( request, response ) {
        $.ajax({
                url: "http://example.com/?json=1&include=title",
                dataType: "json",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    name_startsWith: request.term
                },
            success: function( data ) {
            response( $.map( data.posts, function( item ) {
                return {
                            label: item.title,
                            value: item.title
                        }
                    }));
            }
            });
        },
        minLength: 2,
    });
});     
</script>

Next step is to get this working with custom taxonomies!

share|improve this answer
add comment

I've spent a bit digging around on this and I think I've found your solution! It seems that get_terms()'s name__like parameter is going to be the way to go. name__like's query is as follows (from line 1304 of /wp-includes/taxonomy.php): $wpdb->prepare( " AND t.name LIKE %s", $name__like . '%' );. It will take whatever you give it as the name__like parameter, and add an SQL wildcard, %, to it. This means that it will look for everything that STARTS with what you feed it.

That pretty much settles getting the data...unfortunately it doesn't handle passing it to javascript. I'm not sure exactly how you're handling that aspect of insertion, but I think I would pass out a an array just containing the names and let the discrimination of 'do I create a new term or use the old one?' be handled on submission. If you tell me which parts of this aren't clear (I'm sure there will be some), I can try to give you some pseudo-code, but I don't have time to write this whole thing up, unfortunately.

share|improve this answer
    
Hi thanks for your suggestions. I couldnt get it working with using name__like although i don't really know what im doing to be honest! I did however get this to work using the JSON API plugin and jquery-ui-autocomplete –  coolGeek Feb 7 '12 at 15:11
    
You should submit your solution as a solution and mark the question solved so that anyone who comes after you looking to do the same thing will have a leg up. –  m0r7if3r Feb 8 '12 at 0:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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