Вывести популярные записи WordPress

function.php

//количество просмотров
function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 просмотров";
    }
        return ' Просмотров: '.$count;
}
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    } else {
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}
//количество просмотров

single.php (этот код будет отлавливать просмотрена страница, либо нет)

<?php setPostViews(get_the_ID()); ?>

index.php и тд

<?php
    $args = array( 'post_type' => 'blog', 'posts_per_page' => 6, 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC' );
    query_posts($args);
    while ( have_posts() ) : the_post();
?>
<div class="news--inner">
    <a class="miniature" href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail('medium_large'); ?>
    </a>
    <div class="text">
        <div class="text-cont">
            <a class="title" href="<?php the_permalink(); ?>">
                <h2><?php the_title(); ?></h2>
            </a>
            <div class="descr">
                <div class="entrytext">
                    <p><?php echo trim_characters(200, '...'); ?></p>
                </div>
            </div>
            <a class="btn-go" href="<?php the_permalink(); ?>"><span>Читать</span></a>
        </div>
    </div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
Контакты

Работаем: с ПН по ПТ, с 08:00 до 17:00 (МСК)
Отдыхаем: в СБ и ВС, чтобы быть в тонусе
и реализовывать самые сложные идеи