Calling from the 2 post in the wordpress loop

Asked

Viewed 434 times

1

I am making a loop in wordpress using Wp_query and need to list me only from the 2 post, ignore the 1 first post.

In the past I used query_posts('offset') to do this, but using wp_query I’m not getting it.

Could someone give me this help to see if I’m doing right?

follows the code:

$args2 = array(
'post_type' => 'post',
'posts_per_page' => '5', // listando 5 posts por página
'offset' => '-1', // mostrando a partir do 2 post.
'meta_query' => array(
    array(
        'key' => 'postagem_destacada',
        'value' => '1',
        'compare' => '=='
    )
)); $query_slider2 = new WP_Query($args2);

help someone?

1 answer

2


Add the "post__not_in" key to your array and specify the ID of the first post.

You can do as in this example:

$query = array(
    'post_type' => 'post',
    'meta_query' => array(
        array(
            'key' => 'postagem_destacada',
            'value' => '1',
            'compare' => '=='
        ),
    ),
    'showposts' => '1',
    'orderby' => 'id',
    'order' => 'asc',
);

$WP_Query = new WP_Query($query);
$WP_Query->the_post();
$ID = $post->ID;

$query['post__not_in'] = array($ID);
$query['posts_per_page'] = 5;
$query['showposts'] = '-1';
$query['order'] = 'desc';

$query_slider2 = new WP_Query($query);
  • didn’t work tried to do the way you put it most didn’t work!

  • Updated code, did not have to test before, try again.

  • Yes, but I’m now with another problem, I just want to list only 2 posts, 2 and 3 of the loop! http://i.imgur.com/iaXBAmz.jpg looks at how it looks like!

  • Okay, if my answer solved your initial problem, I advise you to mark this answer as accepted and open a new topic to your other problem, so we make it easier for other people who have the same problem as you to find a solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.