• Resolved AndersonJo

    (@andersonjo)


    Hello, all. I’m very much a PHP novice, and trying to edit a slider on a website I’ve been assigned to work on. Right now I need to change it so that it displays the six most recent posts except for the newest one. Here’s the current implementation:

    $sticky=get_option('sticky_posts');
    	$args=array(
    		'ignore_sticky_posts'=> 1,
    		'post__not_in' => $sticky,
    		'post_type' => 'post',
    		'paged'=> $paged,
    		'posts_per_page'=> 6
    		);
    	$bizsliderq = new WP_Query($args);

    Is there a way I could make it start with the second most recent post, rather than the first? I’ve seen a few solutions on this board that might be adaptable to this situation, but none have worked thus far. If I need to add any additional pieces of the code or need to supply more information, let me know. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • What is returned when you var_dump($sticky); ? You need to get the post ID of the first post inside of the $sticky variable, and pass that ID into ‘post__not_in’ parameter.

    Right now your passing the entire $sticky variable, and not the post ID.

    Maybe, 'post__not_in' => $sticky->posts[0]->ID ?

    Yes, you can set offset to 1:
    https://codex.www.ads-software.com/Class_Reference/WP_Query

    $sticky=get_option('sticky_posts');
    	$args=array(
    		'ignore_sticky_posts'=> 1,
    		'post__not_in' => $sticky,
    		'post_type' => 'post',
                    'offset' = 1,
    		'paged'=> $paged,
    		'posts_per_page'=> 6
    		);
    	$bizsliderq = new WP_Query($args);
    Thread Starter AndersonJo

    (@andersonjo)

    The offset worked! Thank you very much.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude Newest Sticky Post’ is closed to new replies.