I try to save the taxonomy as a list to_content (for the search engine). Unfortunately, despite the many added, only the last item (taxonomy) appears on the list. What is wrong with the code below? Thank you in advance for your help.
function my_acf_save_post( $post_id ){
$fields =get_the_terms( $post->ID, 'some_taxonomies');
foreach( $fields as $field ): {
$content = $field->name .', ';
}
endforeach;
$new_content = $content;
$my_post = array(
'ID' => $post_id,
'post_content' => $new_content
);
remove_action('save_post', 'my_acf_save_post', 20);
wp_update_post( $my_post );
add_action('save_post', 'my_acf_save_post', 20);
}
add_action('save_post', 'my_acf_save_post', 20);
maybe he’s not picking up the terms
add_action ('acf/save_post', 'my_acf_save_post', 10, 1);
I do not recognize them until I add the last value (1)
Line should be
$content .= $field->name .', ';