我需要在30天之后将自定义帖子类型banner
中的任何帖子转换为草稿,我通过以下功能(操作)执行此操作,但是我需要在25天后发布此帖子发送电子邮件给他那告诉他我们转发到草稿的帖子。
怎么做?
function ads_show_expire(){
global $wpdb;
$result = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type = 'banner' AND post_status = 'publish'");
if( !empty($result)) foreach ($result as $a){
$show_time = get_the_time("Y-m-d", $a->ID );
$show_time=date("Y-m-d", strtotime("+30 day", strtotime($show_time)));
if ( $show_time < date("Y-m-d")){//compare 1 year after post with current time
$my_post = array();
$my_post['ID'] = $a->ID;
$my_post['post_status'] = 'draft';
wp_update_post( $my_post );
}
} // end foreach
}
add_action( 'init', 'ads_show_expire' );
答案 0 :(得分:0)
您需要设置每天执行的cronjob并发送邮件并将该帖子转换为草稿。每当有任何用户访问该页面时,您编写的代码将被执行。因此,最好的解决方案是为此创建cron-job。
何时获得25天的条件 $ where。=&#34;和日期(post_date)=&#39;&#34; 。日期(&#39; Y-m-d&#39;,strtotime(&#39; -25天&#39;))。 &#34;&#39;&#34 ;;
`if ( $show_time < date("Y-m-d")){//compare 1 year after post with current time
$my_post = array();
$my_post['ID'] = $a->ID;
$my_post['post_status'] = 'draft';
wp_update_post( $my_post );
$user_info = get_userdata($a->post_author);
$email = $user_info->user_email;
}`
答案 1 :(得分:0)
它可能对你有帮助,
<?php // FOR DATABASE OPERATION
include('../wp-load.php');
// FOR GET_USERDATA FUNCTION & $WPDB
include('../wp-includes/pluggable.php');
wp-includes/author-template.php
//sample email code
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <test@gmail.com>' . "\r\n";
$headers .= 'Cc: test@gmail.com' . "\r\n";
$to = "test@gmail.com";
$subject = "subject text";
$meesage = "test";
$sentmail = mail($to,$subject,$message,$headers);
if($sentmail)
echo $msg = "Mail has been sent successfully...";
else
echo $msg = "Mail has been failed...";
在此之前,你应该使用上面的功能代码。
您可以使用以下功能获取作者电子邮件:
<?php the_author_email(); ?>
要么
<?php get_the_author_meta( 'user_email', $userID ); ?>