admin管理员组

文章数量:1315231

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'
      ));
    }
});

本文标签: post statuschange woocommerce product statut (draft gtpublishpublishgtdraft) depends on the month