Задать вопрос
@sergeiy_permyakov

Как вывести статьи за неделю в get_post?

Подскажите как в get_post получить статьи за неделбю?

есть вот такая функция спараметрами.
$popular_articles = get_posts(
        array(
            'numberposts'   => $limit,
            'category'  => $category_id,
            'meta_key'  => 'views',
//            'meta_key'  => '_recommended_all',  // don't delete
            'orderby'   => 'meta_value_num',
            'order' => 'DESC',
            'suppress_filters' => false
        )


что нужно добавить в параметры?
  • Вопрос задан
  • 82 просмотра
Подписаться 1 Простой Комментировать
Пригласить эксперта
Ответы на вопрос 1
azerphoenix
@azerphoenix
Java Software Engineer
Здравствуйте!
https://wp-kama.ru/function/get_posts#date_query
https://wp-kama.ru/function/wp_query#datetime
А вот, решение - https://stackoverflow.com/questions/25687167/use-g...

//WP_Query Arguments
$args = array(
    'date_query' => array(
        array(
            'column' => 'post_date',
            'after' => '1 week ago',
        )
    ),
    'posts_per_page' => -1
);

//Execute WP_Query (Results placed in $the_query)
$the_query = new WP_Query($args);

//The WordPress Loop
if ($the_query->have_posts()) { //Check if there are any posts returned in $the_query
    echo '<ul>';
    while ($the_query->have_posts()) { //Loop through posts returned in $the_query
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
} else { //If no posts found
    echo "No Posts Found";
}

//Reset WordPress Post Data
wp_reset_postdata();
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы