Making a sticky post the first post in the loop – WordPress

I would like to get help with a issue I’m having with the WordPress sticky posts function.

I cant figure it out how to make the stick post stick to the beginning of the loop. I have a loop similar to his:

Read More
<?php query_posts('cat=10&posts_per_page=3');?>  
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?> 

And I would like it to work like this:

  • Sticky post
  • Ordinary post
  • Ordinary post

Instead for:

  • Ordinary post
  • Sticky post
  • Ordinary post

Thanks for the help!

Related posts

Leave a Reply

2 comments

  1. My solution here http://codex.wordpress.org/Class_Reference/WP_Query

    I made two queries, in this case I’m not using pagination maybe this can help

        $sticky = get_option( 'sticky_posts' );
        $args_nonsticky = array(
            'showposts'     => -1,
            'post__not_in' => $sticky
        );
        $args_sticky = array(
            'posts_per_page' => -1,
            'post__in'  => $sticky
        );
    
        $the_query_sticky = new WP_Query($args_sticky); 
        $the_query_nonsticky = new WP_Query($args_nonsticky);
    
        if(!$the_query_sticky->have_posts() && !$the_query_nonsticky->have_posts()){
            //echo '<h1>NO POSTS FOUND</h1>';
        }else{              
    
        if ( $sticky[0] ) {
        while ($the_query_sticky->have_posts()) : $the_query_sticky->the_post(); 
          //sticky if so...
        endwhile;
        }
    
        while ($the_query_nonsticky->have_posts()) : $the_query_nonsticky->the_post(); 
            // non sticky
        endwhile;
    }