我试图找到一种方法来查询与当前帖子至少有X个相同标签的帖子。This example 很接近,但我不想指定哪个标签。
//List of tag slugs
$tags = array(\'SOMEHOW INCLUDE ALL TAGS\');
$args = array(
\'tag_slug__in\' => $tags
//Add other arguments here
);
// This query contains posts with at least one matching tag
$tagged_posts = new WP_Query($args);
echo \'<ul>\';
while ( $tagged_posts->have_posts() ) : $tagged_posts->the_post();
// Check each single post for up to 3 matching tags and output <li>
$tag_count = 0;
$tag_min_match = 2;
foreach ( $tags as $tag ) {
if ( has_tag( $tag ) && $tag_count < $tag_min_match ) {
$tag_count ++;
}
}
if ($tag_count == $tag_min_match) {
//Echo list style here
echo \'<li><a href="\'. get_permalink() .\'" title="\'. get_the_title() .\'">\'. get_the_title() .\'</a></li>\';
}
endwhile;
wp_reset_query();
echo \'</ul>\';
感谢您的帮助。