使用wp_insert_post插入帖子ID [英] insert post ID with wp_insert_post

查看:101
本文介绍了使用wp_insert_post插入帖子ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在插入新帖子时,如何选择帖子ID,例如:

how can I choose post ID, when inserting new post, ex:

$post = array(
'ID'                =>  3333,
'comment_status'            =>  'open',
'post_content'      =>  'hi world!',
'post_name'         =>  'title_1',
'post_status'       =>  'publish',
'post_title'        =>  'sdfsfd fdsfds ds',
'post_type'         =>  'post',
);  

$post_id = wp_insert_post($post);

想要插入ID = 3333的新帖子

want to insert new post with id = 3333

推荐答案

对不起,朋友们,不可行.这是开发人员在法典上说的:

Sorry buddy, not doable. Here is what the devs say at the codex:

重要:为$ post ['ID']设置值将不会创建具有该ID号的帖子.设置此值将导致函数使用该ID号和$ post中指定的其他值来更新该帖子.简而言之,要插入新帖子,$ post ['ID']必须为空白或完全未设置.

IMPORTANT: Setting a value for $post['ID'] WILL NOT create a post with that ID number. Setting this value will cause the function to update the post with that ID number with the other values specified in $post. In short, to insert a new post, $post['ID'] must be blank or not set at all.

http://codex.wordpress.org/Function_Reference/wp_insert_post

这篇关于使用wp_insert_post插入帖子ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆