WordPress添加了定期发布文章的任务publish_future_post
优采云 发布时间: 2020-08-08 00:40许多主题都具有此功能,可以定期发布WordPress文章. 这是常规发布的原则. WordPress发布是将post_status字段设置为发布,并将post_date设置为发布时间. 如果您需要定期发布,则只需将post_date字段设置为将来的某个时间,该文章将在该时间自动发布. 那如果文章发表时我们需要做些什么呢?
您需要在此处使用WordPress挂钩. publish_future_post挂钩是在定期发布文章时执行的挂钩.
例如,提交一个熊掌编号.
function send_xzh($postid){
$urls = array(
get_permalink($postid),
);
$api = 'http://data.zz.baidu.com/urls?appid=你的APPID&token=你的token&type=推送选项';
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
//echo $result; //要不要判断提交结果自己选择,这里不判断
}
为上述方法添加一个钩子.
add_action( 'publish_future_post', 'send_xzh' );
通过这种方式,可以在定期发布文章时将其自动提交给百度熊掌.