Snippets

Willy Bahuaud Améliorer la fonctionnalité des « contenus à la une » de WordPress / Improve WordPress “Sticky Posts” feature

You are viewing an old version of this snippet. View the current version.
Revised by Willy Bahuaud 3969120
<?php

add_filter( 'query_vars', 'sticky_offset_query_var' );
function sticky_offset_query_var( $vars ) {
    $vars[] = 'ppp_include_sticky';
    return $vars;
}

add_filter( 'the_posts', 'sticky_count_offset', 10, 2 );
function sticky_count_offset( $posts, $q ) {
    if ( $q->get( 'ppp_include_sticky' )
      && 0 < $q->get( 'posts_per_page' )
      && false == $q->get( 'ignore_sticky_posts' ) ) {
        $posts = array_slice( $posts, 0, $q->get( 'posts_per_page' ) );
    }
    return $posts;
}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.