Tell us what you are trying to do?
https://toolset.com/forums/topic/pre-selection-of-taxonomy-items-in-the-post-form-for-registration/
The last time I asked a question, there was an answer, but I couldn't apply it.
It's because I don't know how to use cred_save_data.
Please explain in detail with actual application.
This is the form's expert mode code
[credform]
[cred_field field='form_messages' class='alert alert-warning']
<div class="form-group">
<label for="%%FORM_ID%%_contents-category">[cred_i18n name='contents-category-label']컨텐츠 카테고리[/cred_i18n]</label>
[cred_field field='contents-category' force_type='taxonomy' output='bootstrap' display='select' single_select='true']
</div>
<div class="form-group">
<label for="%%FORM_ID%%_post_title">[cred_i18n name='post_title-label']컨텐츠 제목[/cred_i18n]</label>
[cred_field field='post_title' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label for="%%FORM_ID%%_post_content">[cred_i18n name='post_content-label']컨텐츠 내용[/cred_i18n]</label>
[cred_field field='post_content' output='bootstrap']
</div>
[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
[/credform]
The code below is to select the taxonomy.
[cred_field field='contents-category' force_type='taxonomy' output='bootstrap' display='select' single_select='true']
Instead of being selective, I want to pre-specify certain items.
Of course, this part is not visible to the user.
The taxonomy item is
label : 비데오
slug :video
What is the link to your site?
hidden link
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
As you can see with the official Doc:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
This hook allows doing a custom action when post data is saved to database.
So, once you submit the form and post is saved to the database the above hook you can use for instance to change post title.
Assuming the term slug "viedo" is belongs to the taxonomy "contents-category".
You can assign the default term using the "cred_save_data". You should add the custom code to the "Custom Code" section offered by Toolset:
add_action('cred_save_data', 'func_set_default_terms_when_form_submit',10,2);
function func_set_default_terms_when_form_submit($post_id, $form_data) {
$forms = array( 99999);
if ( in_array( $form_data['id'], $forms ) ) {
$tax_slug = 'contents-category';
$term_slug='video';
wp_set_object_terms($post_id,$term_slug, $tax_slug);
}
}
Where:
- Change 99999 with your original form ID.
The above code with run when you submit the form and assign the video term to newly post added for the form ID 99999.
My issue is resolved now. Thank you!