admin管理员组文章数量:1122846
I have this code:
<?php $most_popular_args = array(
'post_type' => 'post',
'posts_per_page' => 10,
'orderby' => 'meta_value_num',
'meta_key' => 'post_views_count',
'order' => 'DESC'
);
$the_query = new WP_Query( $most_popular_args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php if ( has_post_thumbnail()) {
$medium_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
$domain = get_site_url();
$relative_url = str_replace( $domain, '', $medium_image_url[0] );
}?>
<a href="<?php the_permalink() ?>" class="flex news-small">
<div class="flex flex-col pb-2 pt-1">
<h3 class=" text-[1.2rem] mb-2"><?php the_title() ?></h3>
<div class="mt-auto text-gray-600">
<p class="text-sm">Data: <?php echo get_the_date(); ?>
</p>
<p class="text-sm">Kategoria: <?php list_categories(get_the_category(),true) ?></p>
<?php var_dump(get_post_meta(get_the_ID(),'post_views_count', true ))?>
</div>
</div>
</a>
<?php endwhile; endif?>
But it is not sorting my posts correctly.
I have var_dump()
ed the 'post_views_count'
and see that it is string. Can this be the reason?
But I think that 'orderby' => 'meta_value_num'
treates this value as number? Is in it so?
So how to correctly sort the data. Now it displays in this order which is wrong: 8,6,31,7678,7415,6020
本文标签: wp queryorder metavaluenum not working
版权声明:本文标题:wp query - order meta_value_num not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291294a1928693.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论