Title: Hide last added posts
Last modified: August 19, 2016

---

# Hide last added posts

 *  [mannonero](https://wordpress.org/support/users/mannonero/)
 * (@mannonero)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/hide-last-added-posts/)
 * is there a way to hide 3 last added posts on home page?
    Thanx

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

 *  [FishDogFish](https://wordpress.org/support/users/fishdogfish/)
 * (@fishdogfish)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/hide-last-added-posts/#post-1645281)
 * You can set their “Visibility” to “Private” on the post edit page when you create
   them, or any other time for that matter.
 *  Thread Starter [mannonero](https://wordpress.org/support/users/mannonero/)
 * (@mannonero)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/hide-last-added-posts/#post-1645420)
 * OK, but it’s that I have hot news panel at the top with 3 last added posts and
   below should be following posts, unless there is also a repeat 3 last added posts
   from hot news panel…
    so i’m looking for something like ‘query_posts’ or ‘post__not_in’…?
 *  [FishDogFish](https://wordpress.org/support/users/fishdogfish/)
 * (@fishdogfish)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/hide-last-added-posts/#post-1645504)
 * You and I both need to take a course in PHP.
 *  [Marventus](https://wordpress.org/support/users/marventus/)
 * (@marventus)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/hide-last-added-posts/#post-1645620)
 * Hi Mannonero,
 * Indeed, you do need php code to accomplish what you’re looking for. In my opinion,
   the best way to accomplish what you desire is to assign a certain category or
   tag to your “hot news” posts, and then only show that category or tag in the “
   hot news panel” and exclude it from The Loop in the home page (index.php). The
   final result would be two loops running simultaneously: one for your hot news
   panel, one for your the rest of your homepage content.
 * Here’s how you do it:
 * **1. By category:**
    _Hot News Panel:_ `query_posts('cat=x');` _ Homepage content:_`
   query_posts('cat=-x');`
 * **2. By tag:**
    _Hot News Panel:_ `query_posts('tag=y');` _Homepage content:_
 *     ```
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $args=array(
          'tag__not_in' => array(y),
          'paged'=>$paged,
          );
       query_posts($args);
       ?>
       ```
   
 * Bear in mind that you need to replace “x” and “y” with the category ID number
   and the tag ID number (respectively) assigned to your hot news. You can retrieve
   the category or Tag ID from the WP admin panel, under “Posts” –> “Categories”
   and “Posts” –> “Post Tags.”
    Also, don’t forget you need to accompany the corresponding
   code mentioned above with The Loop code, which usually looks like this:
 *     ```
       <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
       ```
   
 * Like I said earlier, you are going to use The Loop code two times: 1. to display
   the Hot News Panel posts; and 2. to display the rest of your content (this version
   of The Loop should already be included in your template).
    That should do the
   trick for you. Let me know if this works or if you run into any problems.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/hide-last-added-posts/#post-1645623)
 * see techniques for avoiding duplicate posts:
    [http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action](http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action)
   particular:
 * > Alternatively you can pass the entire $do_not_duplicate array to $wp_query 
   > and only entries that match your criteria will be returned:
   >     ```
   >     <?php query_posts(array('post__not_in'=>$do_not_duplicate));
   >      if (have_posts()) : while (have_posts()) : the_post();
   >      ?>
   >     ```
   > 
   > Note that instead a string, the query parameter was an associative array, with
   > post__not_in option.
 *  [Marventus](https://wordpress.org/support/users/marventus/)
 * (@marventus)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/hide-last-added-posts/#post-1645624)
 * Yep, resorting to the `$do_not_duplicate` array like Alcymyth suggests is a very
   good idea too, and it simplifies things on the ‘rest of the homepage content’
   side.
    However, you would still have to ‘populate’ the `$do_not_duplicate` array
   with the Hot News posts (i.e., the posts you’re seeking to exclude from the normal
   Loop). The best moment to do that would probably be when calling the posts inside
   the Hot News panel through the 2nd Loop. What do you think, Alcymyth?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/hide-last-added-posts/#post-1645625)
 * the best place to collect the posts already shown, is using the array method 
   with this line `$do_not_duplicate[] = $post->ID;` in the loop(s) that precede
   the loop in which the duplicates should be ‘hidden’.
 * ( [http://codex.wordpress.org/The_Loop](http://codex.wordpress.org/The_Loop) 
   has examples for this )
 * this ‘hiding’ of duplicate posts can be done in (many) consecutive loops – principle:
 * -loop1:
    `while(have_posts()): the_post(); $do_not_duplicate[] = $post->ID; /*
   show content*/ endwhile;` -loop2: `query_posts(array('post__not_in'=>$do_not_duplicate));``
   while(have_posts()): the_post(); $do_not_duplicate[] = $post->ID; /*show content*/
   endwhile;` -loop3: `query_posts(array('post__not_in'=>$do_not_duplicate));` `
   while(have_posts()): the_post(); $do_not_duplicate[] = $post->ID; /*show content*/
   endwhile;` -loop4: `query_posts(array('post__not_in'=>$do_not_duplicate));` `
   while(have_posts()): the_post(); /*show content*/ endwhile;`

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

The topic ‘Hide last added posts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 4 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/hide-last-added-posts/#post-1645625)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
