User can add taxonomy

This topic contains 3 reply and 2 voices, and was last updated by Tareq Hasan 10 years, 11 months ago
Viewing 3 Posts - 1 through 3 (of 3 total)
Author Posts
May 7, 2013 at 5:18 pm 3312
Tareq Hasan Hi, Is it possible to let users add a taxonomy after having selected a parent taxonomy ? I mean, I have taxonomies as country -> state. After selected a state, if city doesn't already exist as taxonomy, then add it to the form with a "Insert your city" button.
May 7, 2013 at 7:18 pm 3317
Tareq Hasan Tareq Hasan

Sorry, thats not possible with the builtin plugin functionality. You’ve to build this functionality on your own with the help of documentation.

May 7, 2013 at 7:37 pm 3318
ced ced

Do you mean using a html field or action hook ?

Edit. Sorry never mind. Thought your link was the link to the main doc. Can you give more information on the action hook .

May 7, 2013 at 8:21 pm 3321
Tareq Hasan Tareq Hasan

The action hook field already gives some information about how to work with action hooks.
[php]
add_action(‘HOOK_NAME’, ‘your_function_name’, 10, 3 );
function your_function_name( $form_id, $post_id, $form_settings ) {
// do what ever you want
}
[/php]

So the approach you’ve to take is:
1) Show a category dropdown in this function.
2) Handle the onchange event of the dropdown and send ajax request
3) Check if there aren’t any states for that country and send response
4) Handle the response and show/hide input field for new state
5) Upon submitting the form, use the wpuf_add_post_after_insert hook to create a taxonomy entry and attach to the post id. Example:

[php]
function wpufe_create_tax( $post_id ) {

if ( isset( $_POST[‘your_tax_name_input’] ) ) {
// create your taxnomy and attach to the post id
}
}

add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_create_tax’ );
add_action( ‘wpuf_edit_post_after_update’, ‘wpufe_create_tax’ );
[/php]

Thats all I can help.

Viewing 3 Posts - 1 through 3 (of 3 total)