试试这个
<?php
//List of tag slugs
$tags = array();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$tags[] = $tag->term_id;
}
}
$args = array(
\'tag__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>\';
代码将获取与当前帖子相关的所有标签,搜索具有类似标签的其他帖子,如果有2个或更多标签匹配,则返回帖子。
希望这有帮助。