Skip to content

Instantly share code, notes, and snippets.

@solid-pixel
Created January 20, 2017 18:26
Show Gist options
  • Save solid-pixel/9eab37eeea4b50002d58437f97c7ee71 to your computer and use it in GitHub Desktop.
Save solid-pixel/9eab37eeea4b50002d58437f97c7ee71 to your computer and use it in GitHub Desktop.
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
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment