【问题标题】:Display posts tagged with a specific term显示带有特定术语标记的帖子
【发布时间】:2016-05-20 16:32:08
【问题描述】:

我正在尝试在 WordPress 中显示所有标记为特定术语的帖子,目前它以自定义帖子类型显示我的所有帖子,而不是标记为每个术语的帖子。我有一个名为 taxonomy-clientType.php 的文件,然后这是我用来尝试用正确的帖子填充我的 WP_Query 的代码

$taxonomy = 'clientType';
$tax_terms = get_terms($taxonomy);

$term = get_queried_object();

// Define the query
$args = array(
    'post_type' => 'clients',
    'tax_query' => array(
        'taxonomy' => 'clientType',
        'field' => 'slug',
        'terms' => $term->name
    )
);

$query = new WP_Query( $args );

谁能看出我哪里出错了?

谢谢

【问题讨论】:

  • 这个问题有帮助吗? link

标签: php wordpress custom-taxonomy taxonomy-terms


【解决方案1】:

试试:

$args = array(
    'post_type' => 'clients',
    'tax_query' => array(
        array(
            'taxonomy' => 'clientType',
            'field' => 'slug',
            'terms' => $term->name,
        ),
    ),
);

$query = new WP_Query( $args );

【讨论】:

    猜你喜欢
    • 2013-11-01
    • 2020-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 2022-06-29
    • 1970-01-01
    相关资源
    最近更新 更多