用 wp_insert_post() 创建一个新页面 [英] Create a new page with wp_insert_post ()
本文介绍了用 wp_insert_post() 创建一个新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个 PHP 函数中有以下代码,当我安装允许您创建帖子或页面的插件时,该函数会被激活.
I have the following code in a PHP function that is activated when I install my plugin that lets you create a post or page.
如果 $post_type
为post",则完美运行并制作页面,但如果 $post_type
为page",则它不起作用,不创建页面.:
Works perfect and make the page if the $post_type
is "post", but if the $post_type
is "page", then it does not work, does not create the page.:
$my_post = array(
'post_title' => 'My page Reql',
'post_type' => 'page',
'post_name' => 'my-page',
'post_content' => 'This is my page reql.',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => 1,
'menu_order' => 0
);
wp_insert_post( $my_post );
有什么问题?我找不到解决方案.
What is the problem? I can not find the solution.
非常感谢!
推荐答案
我觉得你也必须设置guid
,像这样
I think you have to set the guid
too, like this
$PageGuid = site_url() . "/my-page-req1";
$my_post = array( 'post_title' => 'My page Reql',
'post_type' => 'page',
'post_name' => 'my-page',
'post_content' => 'This is my page reql.',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => 1,
'menu_order' => 0,
'guid' => $PageGuid );
$PageID = wp_insert_post( $my_post, FALSE ); // Get Post ID - FALSE to return 0 instead of wp_error.
这篇关于用 wp_insert_post() 创建一个新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文