php - WP_Query - 按分类术语的元数据排序
问题描述
我正在尝试使用特定分类法的术语值为 wp_query 订购帖子
每个分类术语都有一个由元数据设置的从 1 到 10 的数字(使用 ACF)
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'meta_key' => 'menu_order',
'orderby' => 'meta_value_num',
),
),
);
$wp_query = new \WP_Query($args);
基本上每个术语都有一个顺序,我希望查询返回所有帖子,但我手动设置了这个顺序!
我尝试过的另一个解决方案是使用https://wordpress.org/plugins/custom-taxonomy-order-ne/'orderby' => 'term_order'
它给出了
$terms = get_terms( 'category',array(
'orderby' => 'term_order'
));
$term_ids = wp_list_pluck( $terms, 'term_id' );
$tax_query = array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $term_ids,
),
);
}
$wp_query = new \WP_Query($args);
解决方案
推荐阅读
- vba - Powerpoint 2016 中的宏不起作用
- ruby - Ruby 中的切换案例
- node.js - Mongoose 不区分大小写的架构
- ajax - Laravel 和 AJAX 401 未经授权
- c# - Linq 在多个字段上加入和分组并截断日期中的时间
- javascript - 从本地磁盘加载图像
- java - oatomcat.jdbc.pool.ConnectionPool :无法创建池的初始连接。Spring Boot + MySql
- polymer - 无法下载 Chromium 设置“PUPPETEER_SKIP_CHROMIUM_DOWNLOAD”环境变量以跳过下载
- python - 如何在具有通用视图的 URL 中使用 slug?
- c - 如何处理 gdb 中的`__int128`?