I have this little code to insert posts via custom form:

 $post = array(
     'post_author' => 1,
     'post_title' => 'my title,
     'post_content' => 'my content',
     'post_category' => array(3),
     'post_type' => 'post',
  );

if ( $post_id = wp_insert_post( $post ) ){
    echo 'post added!';
 }

but now I need to insert the last $post_id to term_relationships table,

basic scheme of term_relationships:

object_id | term_taxnomy_id | term_order
-----------------------------------------

Wordpress have a function to update that table?, or I need to build a custom query?

link|improve this question

feedback

1 Answer

up vote 2 down vote accepted

Check this wp_set_object_terms().

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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