Sticky post in custom loop doens't work (1 post)

  1. george.grigorita
    Posted 3 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by george.grigorita
  • This topic is not resolved
  • WordPress version: 3.4.1