Sjrsmile
Sjrsmile

Reputation: 253

Wordpress loop ignore newest post in query

I'm trying to pull out all of the posts that have a meta value of Main, while trying to ignore the newest post created. I've looked here (WordPress site https://codex.wordpress.org/Class_Reference/WP_Query) but I can't figure out a way to ignore the newest post. It can't be by a set date, because it needs to always ignore the newest post.

                        $args = array(
                            'order'                 => 'DESC',
                            'meta_key'              => 'main_story',
                            'meta_value'            => 'Main',

                            'meta_query'        => array(

                                'relation'      => 'NOT IN',

                                array(
                                    'key'             => 'main_story',
                                    'value'           => Main,
                                    'posts_per_page'  => 1,
                                    'order'           => 'DESC',
                                    ),

                                )
                            );

I thought trying it this way not not get the newest post, but it hasn't worked. Is there an opposite of getting the meta_query, like ignore_meta_query, but you know, that works?

Upvotes: 0

Views: 171

Answers (1)

rnevius
rnevius

Reputation: 27092

There are a lot of issues with your posted code...but you're looking for the offset parameter of WP_Query.

offset (int) - number of post to displace or pass over. Warning: Setting the offset parameter overrides/ignores the paged parameter and breaks pagination. The offset parameter is ignored when 'posts_per_page'=> -1 is used.

$args = array(
    'offset' => 1,
    'posts_per_page' => 1,
    'meta_key' => 'main_story',
    'meta_value' => 'Main',
    'meta_compare' => 'NOT',
);

Upvotes: 1

Related Questions