WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. george.grigorita
    Member
    Posted 1 year 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:

    <?php
    	$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();
    	if($category[0]){
    	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' );
    	endwhile;
    	}
    ?>

    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 1 year ago by george.grigorita
  • This topic is not resolved
  • WordPress version: 3.4.1