If using the block editor, the update is done through the API. It possibly could go directly to wp_insert_post(), which despite its name, also does updates. If you look at the source code for wp_update_post(), it does some minor data juggling before calling wp_insert_post() itself.
If you want to set taxonomy terms for a post, you could use wp_set_post_terms().
Thanks, but still not working. I have tried:
- wp_insert_post( $my_post )
- wp_insert_post( $my_post ) AND wp_set_post_terms ($row->ID);
- wp_insert_post( $my_post ) AND wp_set_post_terms( $row->ID,”, ‘post_tag’, true );
and neither update the tags.
The category continues to update but the post tags remain those of the previous language. So we still don’t know what exactly the “Update” button does.
On submit using the block editor, edit form data is POSTed to the /posts API endpoint as JSON data. Assigned tag IDs are sent under the key “tags”. The WP_REST_Posts_Controller’s update_item() method is called. It in fact does call wp_update_post() after decoding the JSON data and constructing a PHP data array. As I mentioned earlier, after a bit more data juggling, wp_insert_post() is called. After updating the posts table, the function then calls wp_set_post_tags() to assign any tag terms to the post.
Assuming your tags are the default “post_tag” taxonomy and not some similar custom taxonomy, the usual reason for failure to update is your theme or some plugin is interfering. If you switch to twentytwenty theme and deactivate all plugins, you’ll likely find that assigned tags are properly updated. Restore your normal configuration, one module at a time. When tags again fail to update, the last activated module is the cause.
It’s not very clean, but it works
wp_update_post( $my_post );
$tags = wp_get_post_tags($row->ID);
foreach ( $tags as $tag ){
wp_delete_object_term_relationships( $row->ID, $tag->name );
$tag_id_lang = pll_get_term( $tag->term_id , "es" );
$tags_lang = array( $tag_id_lang );
wp_set_post_terms($row->ID, $tags_lang, 'post_tag', true );
}