Support » Fixing WordPress » Sticky post in custom loop doens't work

  • I have a problem with showing sticky posts in a custom loop. This is the code I’m using to for the custom loop:

    	$post_from_cat_a = new WP_Query(array(
    	'category_name' => 'events',
    	'posts_per_page'=> 2,
            'post__in'  => get_option('sticky_posts')
    	if( $post_from_cat_a->have_posts() ){
    	while( $post_from_cat_a->have_posts() ): $post_from_cat_a->the_post();
    	$category = get_the_category();
    	echo '<div class="cat-events">
            <a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a></div>';
    	get_template_part( 'content', 'events' );

    If I include 'post__in' => get_option('sticky_posts') in the wp_query array the sticky post is shown but it doesn’t list the next post in the category. Only the sticky posts appears on the page, it’s kind of ignoring the 'posts_per_page'=> 2 argument.

    Does anyone have any idea why this is happening?

  • The topic ‘Sticky post in custom loop doens't work’ is closed to new replies.