The basic function I'm trying to achieve is to get the tags of a current post, find all posts attached to those tags, but then only return posts that have at least 3 tags in common
I've been playing around with this for a week or so.
Found one snippet here that does the job almost perfectly.
$tags = array( 'bread', 'cheese', 'milk', 'butter');
$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 = 3;
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>';
But as you can see, you have to manually input tag names into the array...so it is doesn't work automatically.
I've tried a few different ways to try and pull the tags from the post automatically but can't get it to work...
My skill is rather limited and have only been able to make some clumsy steps into what turned out to be the wrong direction trying to put tag id's into arrays.
Does anybody have any idea how I could go about achieving this?
Pretty stumped.