Dunno2018
@Dunno2018

Wordpress — Почему выводятся удаленные записи?

Код:
<section>

    <h2>
        Возможно, вам будут полезны эти статьи:
    </h2>

    <div class="articles-list">

        <?php global $post;
        if (false === ($rand_query_results = get_transient('rand_query_results'))) {
            $randargs = array('orderby' => 'rand', 'posts_per_page' => 20);
            $query = new WP_Query;
            $rand_query_results = $query->query($randargs);
            set_transient('rand_query_results', $rand_query_results, 60 * 60 * 12);
        }
        $randomposts = get_transient('rand_query_results');
        $randkey = array_rand($randomposts, 4);
        $fourposts[0] = $randomposts[$randkey[0]];
        $fourposts[1] = $randomposts[$randkey[1]];
        $fourposts[2] = $randomposts[$randkey[2]];
        $fourposts[3] = $randomposts[$randkey[3]];

        foreach ($fourposts as $post) :  setup_postdata($post); ?>

            <?php get_template_part('inc/templates/content'); ?>

        <?php endforeach; ?>

        <?php wp_reset_postdata(); ?>

    </div>

</section>
  • Вопрос задан
  • 41 просмотр
Пригласить эксперта
Ответы на вопрос 1
@IvanMogilev
Backend developer: Wordpress,Yii
$randargs = array('orderby' => 'rand', 'posts_per_page' => 20,'post_status' => 'publish');
Ответ написан
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы