Title: Edit code for related posts
Last modified: August 20, 2016

---

# Edit code for related posts

 *  [jumust](https://wordpress.org/support/users/jumust/)
 * (@jumust)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/edit-code-for-related-posts/)
 * Hi,
    I have a theme with its own related posts code at the end of each post. 
   It gets related posts by tags, but actually I would like to EXCLUDE 2 TAGS.
 * in single.php I found the code:
 *     ```
       <?php $tags = get_the_tags(); ?>
       				<?php if($tags): ?>
       				<?php $related = get_related_posts($post->ID, $tags); ?>
       				<?php if($related->have_posts() && $related->found_posts >= 1 && get_option('reedwan_related') == 'On'): ?>
       ```
   
 * It should not be too difficult but can’t figure it out. Any help?
 * Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Andrew Bartel](https://wordpress.org/support/users/andrew-bartel/)
 * (@andrew-bartel)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/edit-code-for-related-posts/#post-3295792)
 * 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.
 *  Thread Starter [jumust](https://wordpress.org/support/users/jumust/)
 * (@jumust)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/edit-code-for-related-posts/#post-3295794)
 * Thanks, I found out that function. I think we might do something around the tag__in
 * [http://pastebin.com/1t5B87Vt](http://pastebin.com/1t5B87Vt)
 *  [Andrew Bartel](https://wordpress.org/support/users/andrew-bartel/)
 * (@andrew-bartel)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/edit-code-for-related-posts/#post-3295797)
 * 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.
 *  Thread Starter [jumust](https://wordpress.org/support/users/jumust/)
 * (@jumust)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/edit-code-for-related-posts/#post-3295847)
 * 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.

## Tags

 * [post tags](https://wordpress.org/support/topic-tag/post-tags/)
 * [tag](https://wordpress.org/support/topic-tag/tag/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [jumust](https://wordpress.org/support/users/jumust/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/edit-code-for-related-posts/#post-3295847)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
