Last active
June 22, 2024 21:22
-
-
Save moxet/1f8a8095278e17fb51d020b00d1197e9 to your computer and use it in GitHub Desktop.
JFB Hook to add terms from front-end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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