wordpress - wordpress 帖子上的 post_status 没有改变
问题描述
我有一个代码,我使用我的自定义模板插入帖子,除了 post_status 字段之外,一切都有效,我错过了什么吗?
$new_speakerevent = array(
'post_ID' => $page_id,
'post_title' => wp_strip_all_tags('HubName'. ' ' .$date. ' ' .'speakerName'),
'post_content' => '',
'post_status' => 'future',
'post_type' => 'speakers',
'post_author' => 12 //default account is 12
);
$idtoreturn = wp_insert_post( $new_speakerevent );
发生的事情不是未来,而是状态自动更改为 PUBLIC
解决方案
计划在未来的某个日期发布。(未来)
即使在 CODEX 中没有逐字指定这一点,future
帖子状态也会执行WP-Cron来安排帖子,因此如果post_status
设置为future
则post_date
需要设置为将来的日期。(因为默认值是插入帖子的当前日期,其null
值设置为post_date
结果自动回退到post_status => publish
)。
add_action( 'init', 'wpso_67525143' );
function wpso_67525143() {
if ( ! get_page_by_title( 'My Awesome Post Getting Published In The Next +10 days' ) ) {
$args = array(
'post_type' => 'page',
'post_title' => 'My Awesome Post Getting Published In The Next +10 days',
'post_status' => 'future',
'post_date' => date( 'c', strtotime( get_the_date( 'Y-m-d' ) . ' + 10 days' ) ),
);
wp_insert_post( $args );
};
};
另一方面,不是,而是wp_strip_all_tags()
有一个用于清理标题的功能,称为sanitize_title_with_dashes()
。
推荐阅读
- ruby-on-rails - Capybara + Selenium-webdriver + RSpec 文件装置 + SSR 给 Net::ReadTimeout
- python - 设置matplotlib表的行边缘颜色
- excel - 在 SrchRng 中,如果单元格包含数据,则将公式粘贴到右侧
- haskell - haskell 源代码中的内联函数
- git - 如何合并两个分支而不丢失另一个不包含的文件?
- javascript - 当 jquery 在该字段中插入变量时,如何检查输入字段是否为空?
- python - Python:在 API 中放置配置文件的位置
- reactjs - 使用 React 绑定两个输入文本
- ios - 集合视图中行和列之间的意外空格
- java - Java中数组的总和