Skip to content

Instantly share code, notes, and snippets.

@moxet
Last active June 22, 2024 21:22
Show Gist options
  • Save moxet/1f8a8095278e17fb51d020b00d1197e9 to your computer and use it in GitHub Desktop.
Save moxet/1f8a8095278e17fb51d020b00d1197e9 to your computer and use it in GitHub Desktop.
JFB Hook to add terms from front-end
add_action( 'jet-form-builder/custom-action/create_terms', function( $request, $action_handler ) {
$terms = explode(',', $request['terms']);
$taxonomy = $request['tax']; // Replace with your actual taxonomy name
foreach ($terms as $term) {
// Check if the term already exists
$existing_term = term_exists($term, $taxonomy);
// If the term doesn't exist, create it
if ($existing_term === 0 || $existing_term === null) {
wp_insert_term($term, $taxonomy);
}
}
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment