Я получаю дату в виде "Месяц, Год", а затем вот что делаю:
$arr = explode(", ", $date_news);
$mounth = $arr[0];
$year = $arr[1];
switch ($mounth) {
case 'Январь':
$mounth = 1;
break;
case 'Февраль':
$mounth = 2;
break;
case 'Март':
$mounth = 3;
break;
case 'Апрель':
$mounth = 4;
break;
case 'Май':
$mounth = 5;
break;
case 'Июнь':
$mounth = 6;
break;
case 'Июль':
$mounth = 7;
break;
case 'Август':
$mounth = 8;
break;
case 'Сентябрь':
$mounth = 9;
break;
case 'Октябрь':
$mounth = 10;
break;
case 'Ноябрь':
$mounth = 11;
break;
case 'Декабрь':
$mounth = 12;
break;
}
$news = array(
'post_type' => 'news',
'posts_per_page' => 1,
'offset' => $offset,
'monthnum' => $mounth,
'year' => $year
);
$news_query = new WP_Query($news);
while( $news_query->have_posts() ) {
$news_query->the_post();
$post_date = get_the_date('F, Y');
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), false, '');
if ($post_date == $date_news) {
$result[] = array(
"id" => get_the_ID(),
"title" => get_the_title(),
"permalink" => get_permalink(),
"thumbnail" => $thumbnail[0],
"author" => get_the_author(),
"date" => get_the_time('d.m.y'),
"views" => getPostViews(get_the_ID()),
"content" => mb_substr( strip_tags( get_the_content() ), 0, 345 )
);
}
} //end while
wp_reset_postdata();
echo json_encode($result);
wp_die();
Все работает, как надо.