php - 显示一个类别中的事件总数 - 事件日历 Wordpress 插件
问题描述
我正在使用The Events Calendar Wordpress 插件并尝试显示一个类别中的事件总数。目前正在尝试这个:
$args = array(
'post_type' => 'tribe_events',
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'food',
),
),
);
$query = new WP_Query( $args );
然后使用它来显示结果:
<?php echo $query-> found_posts; ?>
我的输出虽然返回 0。我错过了什么吗?
解决方案
弄清楚了!看起来我的第一个 tax_query 数组属性有点偏离。这是修复:
$args = array(
'post_type' => 'tribe_events',
'tax_query' => array(
array(
'taxonomy' => Tribe__Events__Main::TAXONOMY,
'field' => 'slug',
'terms' => 'food'
),
),
);
回显相同的查询显示了正确的帖子数量。
推荐阅读
- python - 'FlatSym' 对象没有属性 'array'
- node.js - React useSelector 第一次返回未定义,然后一切正常
- sql - 选择具有最短日期的第一个非空行(大查询)
- python - 如何获得某些数据的“形状”,以便在 numpy/scipy 中生成类似的随机数
- css - 在 Visual Studio Code 中防止自动分号
- python - 在组合框中更改每个项目的前景色和背景色
- regex - 正则表达式列表/列以逗号分隔
- python - 无法使用 pyodbc python 模块查询 EXEC 命令
- java - 无法在 kotlin 中运行 java 函数
- sql - 没有聚合函数的枢轴