我看了一下主题的代码。功能covernew_get_terms()
函数接受taxonomy
参数,请查看源代码:
/**
* Returns all categories.
*
* @since CoverNews 1.0.0
*/
if (!function_exists(\'covernews_get_terms\')):
function covernews_get_terms( $category_id = 0, $taxonomy=\'category\', $default=\'\' ){
#... rest of the code
}
endif;
默认情况下,使用的分类是
category
, 因此,必须通过以下方式调用函数手动指定要包含的分类法数组:
public function form($instance)
{
$this->form_instance = $instance;
$categories = covernews_get_terms(0, array(\'category\', \'custom_taxonomy1\'));
#... rest of the code
}
}
由于您使用的是自定义帖子类型,因此还必须修改WP\\u查询,因为默认情况下它只检索类型“post”。
// widget-posts-carousel.php
// $all_posts = covernews_get_posts($number_of_posts, $category); #line 61. Replace with:
$all_posts = new WP_Query(array(
\'post_type\' => array(\'post\', \'cptsample\'), # set your CPT here.
\'posts_per_page\' => absint($number_of_posts),
\'post_status\' => \'publish\',
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'tax_query\' =>array(
array(
\'taxonomy\' => get_term(intval($category))->taxonomy,
\'field\' => \'term_id\',
\'terms\' => $category
)
)
));