Skip Navigation

[Resolved] Save value to custom taxonomy term when creating post with CRED form

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by davidS-53 5 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1258859

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!

#1259065

Minesh
Supporter

Languages: English (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?

#1261669

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">
		<label>Locations</label>
		[cred_field field="location" force_type="taxonomy" output="bootstrap" display="select"]
		[cred_field field="location_add_new" taxonomy="location" type="add_new"]
	</div>
#1261671

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

#1261813

Minesh
Supporter

Languages: English (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

#1263739

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 ); 

Cheers!