1
I need to create a term with the same name of the post, for this I’m using the action save_post. The term is normally created but when adding metadata the add_term_meta function does not perform. This is the code.
function create_product_group($post_id){
if(get_post_type($post_id) != 'product'){
return;
}
$product_group = get_term_by( 'name', get_the_title($post_id) , 'product_group');
if(!$product_group){
$product_group_id = wp_insert_term( get_the_title($post_id) , 'product_group', array('description' => get_the_excerpt( $post_id )));
add_term_meta($product_group_id,"book_group_author" , 'Elder Carvalho'); //adiciona autores
add_term_meta($product_group_id,"book_group_image", 'http://teste.jpg'); //imagem do livro
add_term_meta($product_group_id,"book_group_category", 'geral'); //categorias do livro
$product_group = get_term_by('id', $product_group_id, 'product_group');
}
wp_set_object_terms( $post_id, $product_group->term_id , 'product_group');
}
add_action('save_post','create_product_group');
add_term_meta normally executes outside the create_product_group function.
Where am I going wrong?
Exact Ricardo, thanks for your help.
– Elder Carvalho