wordpress 如何按 meta关键字存在或元值等于1对WP查询进行排序

c9qzyr3d  于 2022-11-02  发布在  WordPress
关注(0)|答案(1)|浏览(210)

我有包含所有产品列表的过滤器页面,我有两个选项,第一个选项是最新的另一个选项。在数据库中,帖子 meta存储为is_feature = 1。在wp_query期间,它的唯一获取是feautre =1。实际上,我需要从开始就像is_feature = 1一样的数据,其中帖子没有is_feature ="“或没有is_feature元关键字,它们稍后需要显示is_feature = 1。
这是我的疑问:
第一个

c9x0cxw0

c9x0cxw01#

order_by替换为orderby。使用meta_value作为orderby参数:

  1. $conditions = array(
  2. 'posts_per_page' => 9,
  3. 'paged' => $paged,
  4. 'post_type' => 'custom',
  5. 'meta_key' => 'is_feature',
  6. 'orderby' => 'meta_value',
  7. 'order' => 'DESC',
  8. 'post_status' => "publish"
  9. );

https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters

相关问题