How to modify query on category pages to show only sticky posts?

Just set ‘post__in’ to a null array. add_action( ‘pre_get_posts’, function( \WP_Query $q ) { if( ! is_admin() && $q->is_category() && $q->is_main_query() ) { $sticky_posts = get_option( ‘sticky_posts’ ); //If there are sticky posts if( ! empty( $sticky_posts ) ) { $q->set( ‘post__in’, (array) $sticky_posts ); } //If not else { $q->set( ‘post__in’, array(0) ); } … Read more

ignore_sticky_posts not working with word press version 3.9.1

If you want to totally remove the sticky posts from the query, you need to use post__not_in. The Codex has an example, which you can adapt to your needs: $paged = get_query_var( ‘paged’ ) ? get_query_var( ‘paged’ ) : 1; $sticky = get_option( ‘sticky_posts’ ); $args = array( ‘cat’ => 3, ‘ignore_sticky_posts’ => 1, ‘post__not_in’ … Read more

Exclude Current and Sticky Post

Whenever an array of arguments is a function parameter in a WP core function it is parsed via wp_parse_args and almost always extracted into single variables. I.e. no, you cannot use the same argument twice. What you want to do is something like this: $exclude = get_option( ‘sticky_posts’ ); $exclude[] = get_the_ID(); $args = array( … Read more

ignore_sticky_posts in WordPress 3.0.3?

ignore_sticky_posts was introduced in WordPress 3.1. Before this version, you can use caller_get_posts, which will have the same effect (this option was used when you queried the posts via get_posts(), which uses the same WP_Query class in the background, but should ignore sticky posts). The name was a bit confusing, and thus changed in 3.1.

Exclude expired sticky posts

EDIT Here is another approach to the one in my ORIGINAL ANSWER. Instead of the need to alter the main query and $posts global to remove expired stickies, why not remove the posts entirely from being sticky, ie, unstick the posts which has expired. This way, we do not need to check for expired stickies … Read more