标签是taxonomy called post_tag
. 您可以在中使用它们get_posts()
via the tax_query
.
自从wp_get_post_tags()
返回一个对象数组,由于查询只需要每个对象一个字段,因此需要对其进行清理。
$tag_objects = wp_get_post_tags($post->ID);
$tags = array();
foreach ($tag_objects as $tag_object) {
$tags[] = $tag_object->term_id;
}
$myposts = get_posts(array(
\'numberposts\' => -1,
\'offset\' => 0,
\'category__in\' => array($category),
\'tax_query\' => array(
array(
\'taxonomy\' => \'post_tag\',
\'field\' => \'term_id\',
\'terms\' => $tags,
),
),
\'post_status\'=>\'publish\',
\'order\'=>\'ASC\'
));