Examining the following sample code snippet from the WP codex,
$post = array( 'ID' => [ <post id> ] //Are you updating an existing post? 'post_author' => [ <user ID> ] //The user ID number of the author. 'post_category' => [ array(<category id>, <...>) ] //Add some categories. 'post_content' => [ <the text of the post> ] //The full text of the post. 'post_date' => [ Y-m-d H:i:s ] //The time post was made. 'post_title' => [ <the title> ] //The title of your post. 'post_type' => 'post' 'tags_input' => [ '<tag>, <tag>, <...>' ] //For tags. 'tax_input' => [ array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) ) );
I see that only the categories take their input by IDs.
For some reason, ( which I'd like to know the history behind it as to why), tags and custom taxonomies takes their input differently.
Here, we are looking at 3 different ways to set the taxonomy terms;
For cats, use
'post_category' => [ array(<category id>, <...>) ]
for tags, use,
'tags_input' => [ '<tag>, <tag>, <...>' ]
and finally for CT's, use
'tax_input' => [ array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) )
With this 3 different ways, I think things are getting complicated. It's not that it cannot be done but programmatically, it seems more complicated than it should be.
I thought why don't I just use the Uncategorized Cat ID of 1 here ( within the post wp_insert_post ) just to get the post in, and then take care of the proper cats , tags and custom taxonomies, all using the same function call.
With that in mind, I have 2 choices;
wp set object terms and
wp set post terms
I'd like to know if one is better than the other and why we have two different but very similar ( almost like a subset vs superset ) type situation here.
Which one is recommended to use when managing thousands of posts, and cats, tags programmatically - especially in a migration phase?