简体   繁体   English

没有标题的 WordPress insert_post

[英]WordPress insert_post without title

On the register_activation_hook of my plugin I am adding a post with the following code.在我的插件的 register_activation_hook 上,我添加了一个带有以下代码的帖子。

$details_page = array(
    'post_title'    => 'details',
    'post_content'  => '[auto]',
    'post_type'     => 'page',
    'post_status'   => 'publish',
    'post_author'   => 1,
    'post_category' => array( 3,4 )
);
wp_insert_post($details_page);

It adds the post with the right shortcode in it.它添加了带有正确短代码的帖子。 But now I want to delete the word "Details" on the page.但现在我想删除页面上的“详细信息”二字。 (the post title). (帖子标题)。

I don't know how to do this.我不知道该怎么做。 I thought of getting the post by name in the registration hook and then delete the Title.我想在注册挂钩中按名称获取帖子,然后删除标题。 But I don't know how.但我不知道怎么做。

Found the solution..找到解决办法了。。

$details_page = array(
    'post_title'    => '',
    'post_name'     => 'details',
    'post_content'  => '[auto]',
    'post_type'     => 'page',
    'post_status'   => 'publish',
    'post_author'   => 1,
    'post_category' => array( 3,4 )
);
wp_insert_post($details_page);

the post_title could be empty if you use post_name instead如果您使用 post_name,则 post_title 可能为空

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM