0

Tag-it is a jquery UI plugin that allows assigning tags, exactly like tags system in stackoverflow. https://github.com/aehlke/tag-it/blob/master/README.markdown

My goal is to allow members of my wordpress site to post from front end. To do so, I have created a form with input fields. I get the input content using $_POST['something'].To insert the post data (title, content, custom fields values), I use wp_insert_post function, and it is working well.

And to insert tags for the specific post I use wp_set_object_terms function (since I am using custom post type and a taxonomy for tags). This last function is working well if I assign some sample values to it but I cant get the input values of the tags input created by tag-it. I tried my best to link between the plugin and the PHP code responsible of assigning tags to my post in WP DB.

In fact, in my code source I put:

<ul id="myTags">
</ul>

And this code is transformed by the plugin (after execution) to :

<ul id="myTags" class="tagit ui-widget ui-widget-content ui-corner-all">
<li class="tagit-new">
<input type="text" class="ui-widget-content ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
</li>
</ul>

How can I retrieve the POST variable from this input field as an array, so that I can put it in the parameters of wp_set_object_terms ?

Your usual help is always appreciated.\

1

I added the fieldName parameter to tagit function like this:

<script type="text/javascript">
    $(document).ready(function() {
        $("#myTags").tagit(
        {
        fieldName: "tages[]"
        }
        );
    });
</script>

Now I can echo $_POST['tages']; since the HTML after execution became:

<input type="hidden" style="display:none;" value="d" name="tages">

In addition, $_POST['tages']; is a PHP array which I can directly put in second parameter of wp_set_object_terms.

Thank you very much, some problems take a lot of time to resolve, but only before posting them on SE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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