Skip links

WordPress get recent post except first 3 posts

How to check and get recent post 3 in wordpress? On another way it’s calling exclude posts.I’m going to explain this in 2 methods.First method is getting first 3 posts into an array. When we’re going to display the posts, checking current post ID if exist in that array. If exist continue the loop.If not exist then display the posts.Other method is passing parameter “offset”.

Method – 1

$cat_posts = new WP_Query('posts_per_page=1&cat=2'); //first 1 posts
while($cat_posts->have_posts()) {
   $do_not_duplicate[] = $post->ID;
//Then check this if exist in an array before display the posts as following.
 if (have_posts()) {
    while (have_posts()) {
    if (in_array($post->ID, $do_not_duplicate)) continue; // check if exist first post
    } // end while

Method – 2

In here you can pass parameter “offset” to fetch post query as following.

if ( have_posts() ) {
    while ( have_posts() ) {

This query is telling the loop to only display 5 posts which follow the most recent first post. The important part in this code is “offset” and this magic word is doing the whole thing.