Havi hírlevél az alapok teljesítményéről
In my years of WordPress development, I had honestly never had much use for sticky posts. But there’s always a time to learn something new.
First, let’s clarify the problem at hand. We want to use
WP_Query to get a result set of posts that do not contain any posts that have been marked as sticky.
In my initial attempt at ignoring sticky posts in a WordPress query, I used the
ignore_sticky_posts parameter and thought that would do the trick. Because my requirements were in one area of the front page to show the four most recent posts without any sticky posts, and in another area show the most recent sticky post, using just that parameter didn’t work.
ignore_sticky_posts parameter will take the “sticky” out of the post, but those posts marked as sticky will still appear in the order of their publish date within the query results. For example, if your most recent post is sticky, it will be returned as the first post in a query of the most recent four posts.
The proper way to get a result set of the most recent posts without any sticky posts is to make sure any sticky posts are excluded with the
post__not_inargument. Luckily, getting a list of all of the posts that are marked as sticky is simple. We just call
get_option( 'sticky_posts' ).
Now let’s take what we know and put it into a workable WordPress loop.