using wp_insert_term to create custom terms for a custom taxonomy from frontend form,
I have a form which allows certain roles to add custom terms to a taxonomy.
My taxonomy is called Genre (slug genre)
form method='post' enctype='multipart/form-data'
input type=text value= name=new
input type='submit' name='Save'
/form
I have been going around in circles with this for hours. Ive searched for other questions similar and have tried the suggestions.
I am using https://wordpress.org/plugins/custom-post-type-ui/ to create the custom taxonomies - Was wondering maybe my script is firing before this plugin does and therefore wp_insert_terms happens before the register of the custom taxonomy?
My PHP:
if(isset($_POST['save']) !empty($_POST)) {
$term = ($_POST['new']);
$existent_term = term_exists( $term, 'genre' );
if( $existent_term isset($existent_term['term_id']) ) {
$term_id = $existent_term['term_id'];
} else {
//insert the term if it doesn't exsit
$term = wp_insert_term(
$term, // the term
'genre' // the taxonomy
);
if( !is_wp_error($term ) isset($term['term_id']) ) {
$term_id = $term['term_id'];
}
}
} //end isset
Nothing shows in the error log either.
Has anyone come across this issue before? or is anyone able the assist please
Ive tried things like setting $term = ($_POST['new']);
to $term = music;
and having the input value like input type=text value=music name=new
Also I have tried with an array
wp_insert_term(
$term, // the term
'genre', // the taxonomy
array(
'description' = 'I am description.',
'slug' = 'music',
)
);
Topic front-end terms custom-taxonomy Wordpress
Category Web