Related Post ignore certain tags? (1 post)

  1. fouldsy99
    Posted 1 year ago #

    Hi all,

    I'm seeking some help, I want my related pages to ignore a certain tag in my pages.

    How can I get it ignore tags with "sports" in it for my related posts, below is the code I use for current tags:

    function getRelatedPosts( $count=4) {
        global $post;
        $orig_post = $post;
        $tags = wp_get_post_tags($post->ID);
        if ($tags) {
            $tag_ids = array();
            foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
                'tag__in' => $tag_ids,
                'post__not_in' => array($post->ID),
                'posts_per_page'=> $count, // Number of related posts that will be shown.
            $my_query = new WP_Query( $args );
            if( $my_query->have_posts() ) { ?>
                <div class="small-cat">
                <h2 class="section top-20"><span class="section">Related Posts</span></h2>
    		<div class="small-cat-story"><ul>
                while( $my_query->have_posts() ) {
                $my_query->the_post(); ?>
                    <div class="img-story">
    			<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) { /* if post has a thumbnail */ ?>
    			<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>" class="img-shadow"><?php the_post_thumbnail('small-thumb'); ?></a>
    			<?php } else { ?>
    			<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>" class="img-shadow"><img src="<?php echo bloginfo('template_url'); ?>/images/default145.jpg" /></a>
    			<?php } ?>
    		<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
                <?php }
                echo '</ul></div></div>';
        $post = $orig_post;

    [Moderator Note: No bumping, thank you.]

Topic Closed

This topic has been closed to new replies.

About this Topic