WordPress.org

Forums

Editing the Loop to Exclude a Tag (4 posts)

  1. Evypoo
    Member
    Posted 1 year ago #

    Hello,

    I am having some trouble editing my WP homepage loop. Currently, I have a custom post type called woo_video and on my homepage it shows my latest 9 video posts. However, I would like to add the ability to an exclude a video I post from the homepage (perhaps by tagging it something like "skip home"). However, I would still like it to show in the video categories that it was placed in. My code is as follows:

    <!-- Start the Loop. -->
     <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
     			<!-- PHP Post Code Below. -->
    
     			<?php
     	echo '<div class="home-videos">';
    
     			$args = array( 'post_type' => 'woo_video', 'posts_per_page' => 9 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    
    	echo '<div class="home-post">';
    	echo '<div class="home-post-thumbnail">';
    
    	if ( $woo_options['woo_post_content'] != 'content' ) {
    	                		echo '<a href="' . get_permalink( get_the_ID() ) . '" rel="bookmark" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">' . woo_image_vimeo('meta=' . the_title_attribute( array( 'echo' => 0 ) ) . '&width=310&height=' . $woo_options['woo_thumb_h'] . '&class=thumbnail&link=img&return=true') . '</a>';
    	                	}
    	echo '</div>';
    
    	echo '<div class="home-post-title">';
    	echo get_the_title($ID);
    	echo '</div>';
    	echo '</div>';
    
    endwhile;
    
    	echo '</div>';
    	        ?>
    
     			<!-- End the Loop. -->
     <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
                <!-- End. -->

    It is probably an easy fix but I can't seem to get it to work. I appreciate your help!

    Thank you!

  2. Evypoo
    Member
    Posted 1 year ago #

    Site link for your reference: http://tinyurl.com/la62dgs

  3. bcworkz
    Member
    Posted 1 year ago #

    Once you add the "skip home" tag or what ever, determine the term ID of this tag, let's say it's 101. Add this to your arguments array to exclude videos so tagged:
    'tag__not_in' => array( 101 ),

    This will only affect the template on which this code is used, so just don't use it on the category archive template, only the home template. If the same code is used for both, use different arguments decided by if(is_home())

  4. Evypoo
    Member
    Posted 1 year ago #

    Worked perfectly! Thank you so much!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags