最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

post status - change woocommerce product statut (draft ->publishpublish->draft) depends on the month

programmeradmin3浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I have some seasonal products. I thought using "post expirator plugin" but this not managing the "yearly" options. So I thought doing something like this:

function saison(){

 $current_month = date('M');
    if(  $current_month == 'Dec' || $current_month == 'Jan' ) {
       wp_update_post( array( 
         'ID' => 789,
         'post_status' => 'publish'
      ));
    } else {
        wp_update_post( array( 
         'ID' => 789,
         'post_status' => 'draft'
      ));
    }

}

Someone know how to make something like this in my function.php ?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I have some seasonal products. I thought using "post expirator plugin" but this not managing the "yearly" options. So I thought doing something like this:

function saison(){

 $current_month = date('M');
    if(  $current_month == 'Dec' || $current_month == 'Jan' ) {
       wp_update_post( array( 
         'ID' => 789,
         'post_status' => 'publish'
      ));
    } else {
        wp_update_post( array( 
         'ID' => 789,
         'post_status' => 'draft'
      ));
    }

}

Someone know how to make something like this in my function.php ?

Share Improve this question edited Aug 11, 2018 at 12:11 Lust asked Aug 11, 2018 at 10:34 LustLust 411 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

date('M') => 'Aug' and date('m') => 08

add_action('wp', function(){
    $current_month = date('M');
    if( $current_month == 'Aug' ) {
       wp_update_post( array( 
         'ID' => "product_id",
         'post_status' => 'publish'
      ));
    } else {
        wp_update_post( array( 
         'ID' => "product_id",
         'post_status' => 'draft'
      ));
    }
});
发布评论

评论列表(0)

  1. 暂无评论