i am trying to assign multiple categories to my Custom Post Type using advanced custom field named 'cat'. But there is nothing saving to my categories. Any help?
<?php
// Add an action to run on post save
add_action( 'save_post', 'set_genre_on_save' );
function set_genre_on_save( $post_id ){
// Check the post type
if (is_single('hvm')) {
// Get the custom field data
$custom_field_data = get_post_custom( $post_id );
// Check if there is any category entered in the metabox
if (isset($custom_box_data['cat'])) {
// Save the data (separated by comma) into an array
$genre_array = explode( ',', $custom_box_data['cat'] );
//Set the array values to lower case
foreach ($genre_array as $genre){
$genre = strtolower($genre);
}
// Set the categories for these genres
wp_set_object_terms( $post_id, $genre_array, 'category' );
}
}
}
?>