Title: jamesmoriarty's Replies | WordPress.org

---

# jamesmoriarty

  [  ](https://wordpress.org/support/users/jamesmoriarty/)

 *   [Profile](https://wordpress.org/support/users/jamesmoriarty/)
 *   [Topics Started](https://wordpress.org/support/users/jamesmoriarty/topics/)
 *   [Replies Created](https://wordpress.org/support/users/jamesmoriarty/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/jamesmoriarty/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/jamesmoriarty/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/jamesmoriarty/engagements/)
 *   [Favorites](https://wordpress.org/support/users/jamesmoriarty/favorites/)

 Search replies:

## Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [exclude recent posts in a certain category](https://wordpress.org/support/topic/exclude-recent-posts-in-a-certain-category/)
 *  [jamesmoriarty](https://wordpress.org/support/users/jamesmoriarty/)
 * (@jamesmoriarty)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/exclude-recent-posts-in-a-certain-category/#post-1756587)
 * Hi Adria,
    Any chance you could show how exactly you made these two queries? 
   I have exactly the same problem as yourself. Thanks James
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude most recent posts from only 1 category](https://wordpress.org/support/topic/exclude-most-recent-posts-from-only-1-category/)
 *  Thread Starter [jamesmoriarty](https://wordpress.org/support/users/jamesmoriarty/)
 * (@jamesmoriarty)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/exclude-most-recent-posts-from-only-1-category/#post-1895452)
 * Tried that, but still not working!
 * I also changed ‘loop’ to ‘my_query’ as follows:
 *     ```
       <?php $c=0; $my_query = new WP_Query
       ( array( 'post_type' => 'sport','posts_per_page' => 10 ) );
       while ( $my_query->have_posts() ) : $my_query->the_post();
       if( in_category('15', $post->ID) ) $c++;
       if( in_category('15', $post->ID) && $c < 5 ) skip;?>
       <?php endwhile; ?>
       ```
   
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude most recent posts from only 1 category](https://wordpress.org/support/topic/exclude-most-recent-posts-from-only-1-category/)
 *  Thread Starter [jamesmoriarty](https://wordpress.org/support/users/jamesmoriarty/)
 * (@jamesmoriarty)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/exclude-most-recent-posts-from-only-1-category/#post-1895445)
 * This is in addition to the standard loop, which is further down the page.
 * This is what I have in full:
 *     ```
       <?php $c=0;
       $loop = new WP_Query
       ( array( 'post_type' => 'sport','posts_per_page' => 10 ) );
       while ( $loop->have_posts() ) : $loop->the_post();?>
       if( in_category('15') ) $c++;
       if(  in_category('15') && $c < 5 ) skip;?>
       <li<?php if ( $post->ID == $wp_query->post->ID ) { echo ' class="on"'; } else {} ?>>
       <a href="<?php the_permalink()?>">
       <div class="green">
       <?php echo get_post_meta($post->ID, 'sport_other', true);?>:</div>
       </a></li>
       <?php endwhile; ?>
       ```
   
 * This is the main loop further down the page:
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <?php endwhile; endif; ?>
       ```
   
 * I also have another wp_query before the wp_query above which is as follows:
 *     ```
       <?php $loop = new WP_Query
       ( array( 'post_type' => 'sport', 'cat' => '15', 'posts_per_page' => 4 ) );
       while ( $loop->have_posts() ) : $loop->the_post();?>
       ```
   
 * The above are the 4 posts I am trying to exclude from the second loop!
 * Thanks Esmi for your help.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude most recent posts from only 1 category](https://wordpress.org/support/topic/exclude-most-recent-posts-from-only-1-category/)
 *  Thread Starter [jamesmoriarty](https://wordpress.org/support/users/jamesmoriarty/)
 * (@jamesmoriarty)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/exclude-most-recent-posts-from-only-1-category/#post-1895298)
 * Thanks, but it doesn’t work for some reason. It is including all posts from category
   15, and isn’t excluding any.
 * This is what I have:
 *     ```
       <?php $c=0;
       $loop = new WP_Query
       ( array( 'post_type' => 'sport','posts_per_page' => 10 ) );
       while ( $loop->have_posts() ) : $loop->the_post();
       if( in_category('15') ) $c++;
       if(  in_category('15') && $c < 5 ) skip;?>
       <?php endwhile; ?>
       ```
   
 * Any ideas what may be missing?
    Thanks.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude most recent posts from only 1 category](https://wordpress.org/support/topic/exclude-most-recent-posts-from-only-1-category/)
 *  Thread Starter [jamesmoriarty](https://wordpress.org/support/users/jamesmoriarty/)
 * (@jamesmoriarty)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/exclude-most-recent-posts-from-only-1-category/#post-1895191)
 * Hi esmi,
    Thanks very much for your reply, but I should have included all the
   code that I am using. This query is outside the loop, as the main loop is in 
   action elsewhere on the page.
 * If I use the code you suggest, it upsets the conditional statement below, which
   basically applies the style ‘on’ to the post if it appears elsewhere on the page.
 *     ```
       <?php
       $loop = new WP_Query
       ( array( 'post_type' => 'sport', 'cat' => '-15', 'posts_per_page' => 10 ) );
       while ( $loop->have_posts() ) : $loop->the_post();?>
       <li<?php if
       ( $post->ID == $wp_query->post->ID )
       { echo ' class="on"'; } else {} ?>></li>
       <?php endwhile; ?>
       ```
   
 * Any ideas as to how to make your suggested code work with this?
 * Thanks a million,
    James

Viewing 5 replies - 1 through 5 (of 5 total)