Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

Right there is no big difference between them, actually wp_set_post_terms() uses wp_set_object_terms() but does few extra check for you. That's also noted on wp_set_object_terms() Codex page:

Perhaps the wp_set_post_terms() is a more useful function, since it checks the values​​, converting taxonomies separated by commas and validating hierarchical terms in integers.

http://codex.wordpress.org/Function_Reference/wp_set_object_terms#Notes

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.