sale-bubble sign-up-large

30% Savings on all Shared Hosting packages and billing cycles
Offer is valid for any shared hosting package & billing cycle including 1, 2 and 3 year accounts. Offer is limited to 1 per customer, is a one-time discount and for new accounts only. To take advantage of the offer use PROMO CODE: SAVE30 when placing your order.

How to Exclude Sticky Posts from the Loop in WordPress

Blog - WordPress


Sticky posts is one of the cool features that WordPress has, but sometimes you do not want to have sticky posts in your loop. In this article, we will show you how to completely exclude sticky posts from the loop in WordPress, and we will also show you how you can take away the sticky feature of the post, so it still shows in their natural order.

How to take away the Sticky Ability of the Post

When you are displaying most recent posts in a tab, you do not want the sticky posts to stay sticky. If you do not remove the sticky features, the recent posts area would be useless as all of your sticky posts will crowd this area. This is when query_posts feature comes in handy.

To do this you will need to change your loop to something like this:

<?php
query_posts('caller_get_posts=1');
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

Completely exclude Sticky posts from the Loop

If you are using Sticky posts in a slider, then sometimes you might want to completely exclude your sticky posts from the loop. All what you have to do is edit your custom loop to match with this:

<?php
query_posts(array("post__not_in" =>get_option("sticky_posts")));
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

This code will not display any sticky posts in the post loop.

Source: WP Codex

How to Exclude Sticky Posts from the Loop in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Display the Latest Sticky Posts in WordPress
  2. How to Display Any Number of Posts in a WordPress Loop
  3. How to Make Sticky Posts in WordPress


(read full article on source site)

busy



Disclosure: Content posted to this site is in no way an endorsement for a product or service and may result in compensation from the vendor. Some content contained in this site is syndicated content.