name; // untuk mengecek apakah sudah ada kategori berdasarkan huruf pertaman dari title posts $parent_term = term_exists(pertaman($array_wp[0]['post_title']),'category'); // array is returned if taxonomy is given $cat_exists = $parent_term['term_id']; // get numeric term id if (empty($cat_exists)) { // untuk membuat kategori baru ketika kategori belum ada, ketika sudah ada ini tidak akan bekerja wp_insert_term( pertaman($array_wp[0]['post_title']), 'category', array('slug' => pertaman($array_wp[0]['post_title'])) ); } // untuk menambah kategori ke dalam postingan $term_taxonomy_ids = wp_set_object_terms( $postid, $cat_name, 'category', true ); if ( is_wp_error( $term_taxonomy_ids ) ) { // There was an error somewhere and the terms couldn't be set. } else { // Success! These categories were added to the post. }