0

我有一个名为新闻的自定义帖子类型。在里面,我有两个自定义分类法,称为新闻稿和媒体报道。当我使用此查询查询多个帖子时:

$args = array(
        'post_type' => 'news',
        'news_type' => 'press-releases',
        'posts_per_page' => 15,
        'paged' => $json_api->query->page,
    );

    $query = new WP_Query($args);

它只会将新闻帖子归类为我想要的新闻稿。但是,如果我指定媒体报道中存在的 slug,即使我指定了新闻稿分类法,它也会返回该帖子。例子:

$args = array(
            'name' => $slug,
            'post_type' => 'news',
            'news_type' => 'press-releases',
            'posts_per_page' => 1,
        );
4

1 回答 1

0

你可以试试这个

$args = array(
    'post_type'   => 'news',
    'name' => '$slug,
    'posts_per_page' => 1,
    'tax_query' => array(
        array(
            'taxonomy' => 'news_type',
            'field' => 'slug',
            'terms' => 'press-releases'
        )
    )
);
于 2013-06-28T18:06:45.680 回答