Support » Fixing WordPress » Edit code for related posts

Viewing 4 replies - 1 through 4 (of 4 total)
  • get_related_posts() is not a native WordPress function, you’d have to find it and modify it somehow, preferrably through a child theme or overwriting it if the developer made the function pluggable.

    Thanks, I found out that function. I think we might do something around the tag__in

    http://pastebin.com/1t5B87Vt

    Ok, change this:

    if($tags) {
            foreach($tags as $tag) {
                   $tagsA[] = $tag->term_id;
            }
    }

    To:

    if($tags) {
            foreach($tags as $tag) {
                   if($tag->term_id != 'Tag to exclude 1' && $tag->term_id != 'Tag to exclude 2') $tagsA[] = $tag->term_id;
            }
    }

    I really do recommend extending this function, writing your own and calling that or otherwise not hacking it directly.

    Thanks,
    but it doesn’t look like it’s excluding those tags…

    Example: There are 2 posts with only one same tag (spotlight), all others tags are different. But still they are showing in the related posts.

    Maybe I’m doing something wrong…

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Edit code for related posts’ is closed to new replies.