在WP_Query中包含类别

时间:2018-04-23 04:55:35

标签: php wordpress

我正在查询我的

$posts = new array("71", "10")

$query = new WP_Query(array(
  'posts_per_page' => -1,
  'post_type' => 'Hardware',
  'post__in' => $posts,
));

我还希望在结果中找回我的帖子类别。

有关如何在上述查询中包含此内容的任何建议吗?

1 个答案:

答案 0 :(得分:0)

请使用函数get_the_category($post_id)。你需要传递帖子ID:

if ( $query->have_posts() ) {

    // Start looping over the query results.
    while ( $query->have_posts() ) {

        $category = get_the_category($query->ID)

        // Contents of the queried post results go here.

    }

}