solid-pixel
1/20/2017 - 6:26 PM

Assign Taxonomy Term with same name as Post Object's assigned title

Assign Taxonomy Term with same name as Post Object's assigned title

<?php

// Assign a taxonomy term with the same name as the Course assigned to the Tutor
function create_tutors_course($post_ID) {

  global $wpdb;
  $postObjectID = get_field('tutor_course', false, false); //grab the assigned Course's post ID
  if($postObjectID) {
    $catName = get_the_title($postObjectID); //grab the title of the Course
    wp_set_object_terms($post_ID, $catName, 'course_name'); //course_name is the taxonomy slug
  }

}
add_action('acf/save_post', 'create_tutors_course', 20); // This creates the term on Save

?>