Skip to content

Instantly share code, notes, and snippets.

@westcoastdigital
Last active October 16, 2019 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westcoastdigital/64e0bab53ef0c5414d36b1405c32997d to your computer and use it in GitHub Desktop.
Save westcoastdigital/64e0bab53ef0c5414d36b1405c32997d to your computer and use it in GitHub Desktop.
Poplulate make from parent term of model
<?php
function update_custom_terms($post_id) {
/**
* Define taxonomies
*/
$make = 'make';
$model = 'model';
// only update terms if it's a vehicle-listings post
if ( 'vehicle-listings' != get_post_type($post_id)) {
return;
}
// don't create or update terms for system generated posts
if (get_post_status($post_id) == 'auto-draft') {
return;
}
/*
* Grab the parent term and populate the term
*/
$terms = wp_get_post_terms($post_id, $model);
foreach ($terms as $term) {
if ($term->parent == 0) //check for parent terms only
wp_update_term($term->term_id, $make, array(
'name' => $term->name,
'slug' => $term->slug
)
);
return;
}
}
//run the update function whenever a post is created or edited
add_action('save_post', 'update_custom_terms');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment