Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #205841

    Hello,

    would it be possible to exclude posts that are tagged with a certain tag from the related posts at the bottom of each blog post? (the “You might also like” posts)

    Thank you for your help.

    #206158

    Hi,

    Open includes/related-posts.php and look for lines 44-51:

    $my_query = get_posts(
                        array(
                            'tag__in' => $tag_ids,
                            'post_type' => get_post_type($this_id),
                            'showposts'=>$postcount, 'ignore_sticky_posts'=>1,
                            'orderby'=>'rand',
                            'post__not_in' => array($this_id))
                        );

    Replace them by this:

    $my_query = get_posts(
                        array(
                            'tag__in' => $tag_ids,
                            'post_type' => get_post_type($this_id),
                            'showposts'=>$postcount, 'ignore_sticky_posts'=>1,
                            'orderby'=>'rand',
                            'post__not_in' => array($this_id),
                            'tax_query' => array(
                                array(
                                    'taxonomy' => 'post_tag',
                                    'field' => 'slug',
                                    'terms' => array('_YOUR_UNDESIRED_TAG_'),
                                    'operator' => 'NOT IN'
                                )
                            )
                        ));

    Change _YOUR_UNDESIRED_TAG_ by the tag you want to exclude.

    Regards,
    Josue

    #208013

    Thank you!!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘exclude posts with certain tag from related posts’ is closed to new replies.