我有一个通过自定义表单插入帖子的小代码:
$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!\';
}
但现在我需要将最后一个$post\\u id插入到
term_relationships
桌子
term\\u关系的基本方案:
object_id | term_taxnomy_id | term_order
-----------------------------------------
Wordpress有更新该表的功能吗?,或者我需要构建一个自定义查询?
SO网友:Bashirpour
is_wp_error() 函数在成功时返回post\\u ID。失败时的值0或WP\\U错误。
$post = array(
\'post_author\' => 1,
\'post_title\' => \'my title,
\'post_content\' => \'my content\',
\'post_category\' => array(3),
\'post_type\' => \'post\',
);
$ins_post = wp_insert_post($post);
if(is_wp_error($ins_post)){
echo \'error\';
}else{
echo \'post added! <br>\';
echo \'post_id :\'.$ins_post ;
}