WordPress.org

Ready to get started?Download WordPress

Forums

Add exception for specific tag (2 posts)

  1. yofx
    Member
    Posted 2 years ago #

    I'm using this piece of code to generate Related Posts by looking at the tags of posts. The problem is I have use a tag named featured (id=795) in order for a post to show up in a slideshow. So posts are showing up as related because of that matching Featured tag, even though they are not alike at all.

    So is there an easy to to exclude the tag "featured" in this 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 >= 3 && get_option('pyre_related') == 'On'): ?>

    I am guessing there needs to be a tag__not_in or something similar included but I just don't know PHP well enough to know the syntax.

  2. yofx
    Member
    Posted 2 years ago #

    I found the answer. the get_related_posts function was found in the functions.php file where I had to edit the code to exclude the id of the tag.

    $args = wp_parse_args($args, array(
    		'showposts' => 4,
    		'post_type' => $post_types,
    		'post__not_in' => array($post_id),
    		'tag__in' => $tagsA,
    		'tag__not_in' => 795,
    		'ignore_sticky_posts' => 1,
    	));

Topic Closed

This topic has been closed to new replies.

About this Topic