Skip Navigation

[Résolu] Save value to custom taxonomy term when creating post with CRED form

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 5 réponses, has 2 voix.

Last updated by davidS-53 Il y a 2 années et 3 mois.

Assigned support staff: Minesh.


I have a custom taxonomy called location. When adding a new location term, I need to save a value to a taxonomy field called "term-creator-id". I've found the create_category hook and written this up roughly:

function sf_save_term_creator_id( $term_id, $taxonomy_term_id ) {
    $term_creator_id = '30';
    update_term_meta( $taxonomy_term_id, 'wpcf-term-creator-id', $term_creator_id );
add_action( 'create_category', 'sf_save_term_creator_id', 10, 2 );

However it doesn't seem to do what's needed.

Is there a separate hook I should be using? I couldn't find anything in the docs- could you possibly point me in the right direction please? Cheers!



Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I would like to know here that which action you are targetting when you are in admin section and user create new taxonomy term or when you are using forms?


I'm trying to get this to work when a new location is added via a CRED form. Here's how it's added to my form:

	<div class="form-group">
		[cred_field field="location" force_type="taxonomy" output="bootstrap" display="select"]
		[cred_field field="location_add_new" taxonomy="location" type="add_new"]

So when a user adds a new location using the "location_add_new" field.



Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - you should use the following function to assign the value to your custom term field automatically when a new term is created using "Add New" button.

For example:

function action_create_term_location $term_id, $tt_id ) { 
  $term_creator_id = '30';
   update_term_meta( $term_id, 'wpcf-term-creator-id', $term_creator_id );
add_action( "create_location", 'action_create_term_location ', 10, 2 ); 

More info:
=> hidden link


Works fine, had to fix a missing bracket/extra space though:

function action_create_term_location ( $term_id, $tt_id ) { 
  $term_creator_id = '30';
   update_term_meta( $term_id, 'wpcf-term-creator-id', $term_creator_id );
add_action( 'create_location', 'action_create_term_location', 10, 2 );