I have this script (found online) to import the values of an input form field as a taxonomy term. I got it working, but now I'd like to import/save the values of multiple form fields. Now all it does is import the value of the field 'input_name' as a taxonomy term. But, lets say, I'd like to import the values of 'input_name2' and 'input_name3' as well. I should be able to do that with an array
and a foreach
right? I am just quite new to PHP so could someone help me out here? Below is the code (also notice the replace function to replace spaces with -). Thanks a lot!
//Custom field to custom taxonomy script
$parent_term2 = term_exists( 'the_tax' ); // array is returned if taxonomy is given
$parent_term_id2 = $parent_term2['term_id']; // get numeric term id
$plaats2 = $_POST['input_name'];
$plaatsn2 = ucwords(strtolower( $plaats2 ));
$plaatsn3 = array(" ");
$plaatsn4 = array("-");
$plaatsn5 = str_replace($plaatsn3, $plaatsn4, $plaatsn2);
$cid2 = wp_insert_term(
$plaatsn5, // the term
'the_tax', // the taxonomy
array(
'description'=> 'Tax term '.$plaatsn5.'!',
'slug' => $plaatsn5,
'parent'=> $parent_term2['term_id']
)
);
wp_set_object_terms( $listing_id, $plaatsn5, 'the_tax', false);