How to exclude sticky posts from the loop?

How to exclude sticky posts from the loop?

Travis’ answer is fine if you’re building your own query, for a secondary loop perhaps, but if you need to modify your main blog query, you can use pre_get_posts to filter out the sticky posts.

How to exclude sticky posts from the WP query?

I took @tnorthcutt’s answer from WordPress’ Codex on query_posts () about Sticky Parameters and created a tandalone example you can drop as test.php into your website’s root and see it run by navigating to a URL like this, with your domain substituted:

Why are my recent posts sticky on WordPress?

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 feature, the recent posts area would be useless as all your sticky posts will crowd this area. This is where query_posts feature comes in handy.


What does offset = 1 mean in WP query?

Also I wanted to make sure you know that starting with an offset=1 (instead of offset=0) means you’ll be excluding the first post that otherwise would be returned by the query. Of course you’ll still get the number of posts specified by $number assuming you have that many applicable posts +1. So here’s the code:

Why do I need an array for WP _ query ( )?

Some notes on the code; I had to use an array equivalent of the query string you passed to WP_Query () because the post__no_in argument can’t be passed in as a comma delimited string (not sure why, probably an oversight?).

Can you exclude sticky posts from a query in WordPress?

Looks like that will only work on 3.0 or greater, though: http://wordpress.org/support/topic/excluding-sticky-posts-using-query_posts Edit: in response to your comment below, try this (I’m not sure this will work, but hopefully it will get you started):

What are the different types of sticky posts?

This includes several different classes of value: post, hentry (for hAtom microformat pages), category-X (where X is the slug of every category the post is in), and tag-X (similar, but with tags). It also adds “sticky” for posts marked as Sticky Posts.

Can you’exit’a loop in PHP?

One thing that was hinted at but not explained is that the keyword can take a numeric value to tell PHP how many levels to break from. For example, if you have three foreach loops nested in each other trying to find a piece of information, you could do ‘break 3’ to get out of all three nested loops.

How to get out of a foreach loop in PHP?

For example, if you have three foreach loops nested in each other trying to find a piece of information, you could do ‘break 3’ to get out of all three nested loops. This will work for the ‘for’, ‘foreach’, ‘while’, ‘do-while’, or ‘switch’ structures.