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 questionI 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 questionI 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 badges1 Answer
Reset to default 0date('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'
));
}
});