Calling from 2 post in the wordpress loop

0

I am looping in wordpress using WP_query and need to list me only from 2 post, ignore the first 1 post.

Previously I used the 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 it right?

follow 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);

Does anyone help?

    
asked by anonymous 22.07.2015 / 19:39

1 answer

1

Add to your array the "post__not_in" key 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);
    
22.07.2015 / 19:47