admin管理员组文章数量:1415475
I have a requirement where I need to show all posts having thumbnail first and ordered by title and then remaining posts ordered by title Below is the code I tried
$the_page = (get_query_var('paged')) ? get_query_var('paged') : -1;
$args = array(
'post_type' => "listings",
'post_status' => 'publish',
//'meta_key' => '_thumbnail_id',
'order' => 'DESC',
'posts_per_page' => 88,
'paged' => $the_page,
'orderby' => 'meta_key title',
'meta_query' => array( //query post based on meta key
array(
'relation' => 'OR', // add condition if meta key is exists or not
array(
'key' => '_thumbnail_id',
'compare' => 'NOT EXISTS' // include post without _thumbnail_id key
),
array(
'key' => '_thumbnail_id',
'compare' => 'NOT NULL' // include post without _thumbnail_id key
)
)
)
If we look closely , I have set orderby='meta_key title'
and meta_key
is not one of supported arguments in WP_Query Documnentation hence its being removed by WP_Query while generating sql.
In generated sql only ORDER BY wp_posts.post_title DESC
is generated.
My question is: 1. do we have any other way to get posts with thumbnail first in the list ? 2. do we have a way to order result by field that is not listed in WP_Query supported arguments list ?
Any help or hint is appreciated :)
Thanks in advance.
本文标签: postsOrder by metakey field in Wordpress not metavalue field value
版权声明:本文标题:posts - Order by meta_key field in Wordpress not meta_value field value 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745221615a2648421.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论