Displaying custom post type according to maximum view count field
For displaying custom post type according to maximum view count field
<?php
// args
$args = array(
‘post_type’ => ‘anime_series’,
‘meta_key’ => ‘view_count’,
‘orderby’ => ‘meta_value_num’,
‘order’ => ‘desc’
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href=”<?php the_permalink(); ?>”>
<?php the_title();
$id = get_the_ID();
echo get_post_meta($id, ‘view_count’, 1);
?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post().
?>