wordpress 添加文章代码及定时发布文章代码

有时候我们需要自己写代码添加文章,使用下面代码即可,也可也发布定时文章,

$my_post = array (
    'post_title' => '文章标题',
    'post_content' => '文章内容',
    'post_status' => 'publish', //如果要发布计划 填写future
    'post_author' => 1,
    'post_category' => array (1) ,
    'post_date'=>date('Y-m-d H:i:s',$time),//可不写,如发布计划,此处的时间最好与wp_schedule_single_event 内的时间相同
);
			
$postID=wp_insert_post( $my_post );

//添加计划 如上面 post_status 为future 应执行下面代码,否则计划发布失败
wp_schedule_single_event( $time, 'publish_future_post', array( $postID ) );

本文收集于网络,仅供技术交流使用,本站不拥有所有权,不承担相关法律责任。如果发现本站有涉嫌抄袭的内容, 欢迎发送邮件至 admin@webse.cn 举报,一经查实,本站将立刻删除涉嫌侵权内容,本文链接:https://webse.cn/16359.html

(3)
打赏 微信扫一扫 微信扫一扫
上一篇 2020-08-05 08:40
下一篇 2020-08-19 11:07

相关推荐

发表回复

登录后才能评论