WordPress.org

Forums

Related Post ignore certain tags? (1 post)

  1. fouldsy99
    Member
    Posted 11 months 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;
            $args=array(
                'tag__in' => $tag_ids,
                'post__not_in' => array($post->ID),
                'posts_per_page'=> $count, // Number of related posts that will be shown.
                'ignore_sticky_posts'=>1
            );
            $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>
                <?php
                while( $my_query->have_posts() ) {
                $my_query->the_post(); ?>
                <li>
                    <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 } ?>
    		</div><!--img-story-->
    		<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
                </li>
                <?php }
                echo '</ul></div></div>';
            }
        }
        $post = $orig_post;
        wp_reset_query();
    }

    [Moderator Note: No bumping, thank you.]

Reply

You must log in to post.

About this Topic