1

I want to add my first post of current date to drafts and when the second post is added, I want both of them to be published together. Below is my code and I am confused on how to post them in draft and publish them accordingly

function gk_post_status(){

$year = date("Y");
$month = date("m");
$day = date("d");
$posts = array(
    'date_query' => array(
        'year'  => $year,
        'month' => $month,
        'day'   => $day,
    ));

$the_query = new WP_Query( $posts );
if( $the_query->have_posts() ){
    //Publish both posts when clicked on "Publish"
}else{
    //Save post in draft when clicked on "Publish"
}

}
add_action( 'init', 'gk_post_status' );

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.