/*
Theme Name: JNews - Child Theme
Version: 1.0.0
Theme URI: http://themeforest.net/?ref=jegtheme
Description: A basic starter child theme for customization purpose of JNews theme.
Author: Jegtheme
Author URI: http://themeforest.net/user/jegtheme?ref=jegtheme
Template: jnews
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/

/* ------------------------------------------------------------------------- *
 *  Theme customization starts here
/* ------------------------------------------------------------------------- */

add_action('init', function() {
  $args = [
    'post_type' => 'post',
    'post_status' => ['publish', 'draft'],
    'date_query' => [
      'after' => date('Y-m-d', strtotime('-6 months'))
    ],
    'posts_per_page' => -1
  ];
  $query = new WP_Query($args);
  foreach ($query->posts as $post) {
    if (strtotime($post->post_date) > strtotime('-6 months') && $post->post_status === 'publish') {
      wp_update_post(['ID' => $post->ID, 'post_status' => 'draft']);
    } elseif (strtotime($post->post_date) <= strtotime('-6 months') && $post->post_status === 'draft') {
      wp_update_post(['ID' => $post->ID, 'post_status' => 'publish']);
    }
  }
});
