WordPress.org

Ready to get started?Download WordPress

Forums

Multiple loops and sticky posts (5 posts)

  1. cooperanet
    Member
    Posted 4 years ago #

    Hi,

    I have two loops in a page of my custom theme. For each loop, I use the WP_Query function.

    The first loop displays all the posts from all the categories, and when there are sticky posts, they come on the top of the list. That's normal.

    The second loop displays four posts from one category only (like a featured category). But when there are sticky posts in this category, i'd like to see them on the top of this section. But currently, they just appears in their normal order (by date).

    This is the code of my second loop:

    <?php
    $args = array('cat' => 3, 'posts_per_page' => 4, 'post_status' => 'publish' );
    $highlights = new WP_Query($args);?>
    <?php while ( $highlights->have_posts() ) : $highlights->the_post() ; ?>
    <!-- title, content, image, etc. -->
    <?php endwhile; ?>

    Does anyone know how to force the sticky posts to appear first?

    Any help would be greatly appreciated!

    Thanks!

  2. childheart82
    Member
    Posted 4 years ago #

    Same issue here... can anyone help us?

  3. vtxyzzy
    Member
    Posted 4 years ago #

    See if adding 'caller_get_posts=0' to the arguments will help.

    $args = array('cat' => 3, 'posts_per_page' => 4, 'post_status' => 'publish', 'caller_get_posts' => 0 );

  4. childheart82
    Member
    Posted 4 years ago #

    Thank you vtxyzzy!
    I added calleg_get_posts to my args as follows:
    $args = array(
    'cat'=>'3,4',
    'posts_per_page' => 5,
    'post_status' => 'publish',
    'caller_get_posts'=>0
    );
    but still sticky posts don't show at the top.. :°°

  5. vtxyzzy
    Member
    Posted 4 years ago #

    I wonder if something in your theme, or in a plugin might be interfering. Try switching to the default theme to see if the problem goes away. If not, try disabling all plugins.

Topic Closed

This topic has been closed to new replies.

About this Topic