【问题标题】:Display total number of events in a category - Events Calendar Wordpress Plugin显示类别中的事件总数 - 事件日历 Wordpress 插件
【发布时间】:2020-09-08 01:46:59
【问题描述】:

我正在使用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。我错过了什么吗?

【问题讨论】:

    标签: php wordpress custom-wordpress-pages


    【解决方案1】:

    想通了!看起来我的第一个 tax_query 数组属性有点偏离。这是修复:

    $args = array(
        'post_type' => 'tribe_events',
        'tax_query' => array(
            array(
                'taxonomy' => Tribe__Events__Main::TAXONOMY,
                'field' => 'slug',
                'terms' => 'food'
            ),
        ),
    );
    

    回显相同的查询会显示正确的帖子数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多