Forums

get sticky posts outisde the loop (3 posts)

  1. jogol
    Member
    Posted 1 year ago #

    Hi, i tried getting the sticky posts before the loop like this:

    <?php
        /* Get all sticky posts */
        $sticky = get_option( 'sticky_posts' );
    
        /* Sort the stickies with the newest ones at the top */
        rsort( $sticky );
    
        /* Get the 5 newest stickies (change 5 for a different number) */
        $sticky = array_slice( $sticky, 0, 5 );
    
        /* Query sticky posts */
        query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
        ?>

    But when I do so the main loop is empty and no other posts are displayed.

    Any ideas?

    Thanks in advance,
    Jogol

  2. jogol
    Member
    Posted 1 year ago #

    I want to add that I´m trying this on the Twenty Ten 1.1 template, in loop.php.

    Thanks!

  3. alesub
    Member
    Posted 1 year ago #

    Hi there!

    You might forgot one important instruction before displaying the sticky posts:

    wp_reset_query();

    Let me know if that solves the problem!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.