• Resolved fas.khan

    (@faskhan)


    Hi all,

    I wrote this code to show Sticky Post first (if there is any) and otherwise, just show the post, which is written latest.

    I have to just show one post on the page (either sticky or latest). To achieve it, I wrote the following code:-

    The problem is that It is not showing any sticky post. It does show me latest post properly but is not picking the sticky post.

    I would be very thankful, if you can pick the problem or if you want, you can propose a better code! …

    <?php
         $recentPosts = new WP_Query();
         $recentPosts->query("showposts=1&category_name='ewp-news'&orderby=date&array('post__in'=>get_option('sticky_posts'))");
    
         $stickyCheck = false;
         while ($recentPosts->have_posts()) : $recentPosts->the_post(); 
    
            // The first one is always a  Sticky, so if there is a sticky, it will check it and let it pass!
    
            if (!($stickyCheck))
    	{
    ?>
    
                   <?php
    
                        // Title and Excerpt of the Post.
    
                    ?>
    
                <?php
    	}
    
            //if this post was a sticky post! then make it true and dont let another one show itself!
    
            if (is_sticky())
    	   $stickyCheck = true;
    
            ?>
          <?php endwhile; ?>

    I will be very thankful to you, if you can help me in this.

    Many Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sticky Code to show Stick post first is not working’ is closed to new replies.