Your code doesn’t make sense.
- You use
query_posts()
, which you should never do, but all that
does is clobber the main query. You don’t use the clobbered query though. - You then use
get_posts()
with an undefined (so far as code posted
indicates) argument list, so it is not going to return what you
expect.
I think that what you are looking for is this:
$args = array(
'posts_per_page' => 4, /* get 4 posts, or set -1 for all */
'orderby' => 'meta_value_num', /* this will look at the meta_key you set below */
'meta_key' => 'post_views_count',
'order' => 'DESC',
'post_type' => array('news','database'),
'post_status' => 'publish'
);
$myposts = new WP_Query( $args );
if ($myposts->have_posts()) {
while ($myposts->have_posts()) {
$myposts->the_post(); ?>
<a href="https://wordpress.stackexchange.com/questions/145642/<?php the_permalink(); ?>"><?php the_title(); ?></a><?php
}
}