• Your code for retrieve_sticky_posts() includes the following:

    // If any posts have been excluded specifically, Ignore those that are sticky.
    if ( !empty($sticky_posts) && !empty($q['post__not_in']) ) {
        $sticky_posts = array_diff($sticky_posts, $q['post__not_in']);
    }
    

    However, the code in the functio never defines $q, but since you’re checking the whole thing with empty() it doesn’t crop up as an error. This casues explicitly excluded sticky posts to still show up.

    It should be this:

    // If any posts have been excluded specifically, Ignore those that are sticky.
    if ( !empty($sticky_posts) && !empty($wp_query->query_vars['post__not_in']) ) {
        $sticky_posts = array_diff($sticky_posts, $wp_query->query_vars['post__not_in']);
    }
    
    • This topic was modified 1 year, 11 months ago by Doug Wollison.
Viewing 1 replies (of 1 total)
  • Thread Starter Doug Wollison

    (@dougwollison)

    Also, I’d suggest tweaking how you’re fetching the $stickies list; you’re calling get_posts which by default supresses filters, whereas the native wordpress method inherits the settings of the original query.

    $stickies = get_posts(
    	array(
    		'post__in'               => $sticky_posts,
    		'post_type'              => $q['post_type'],
    		'post_status'            => 'publish',
    		'posts_per_page'         => count( $sticky_posts ),
    		'suppress_filters'       => $q['suppress_filters'],
    		'cache_results'          => $q['cache_results'],
    		'update_post_meta_cache' => $q['update_post_meta_cache'],
    		'update_post_term_cache' => $q['update_post_term_cache'],
    		'lazy_load_term_meta'    => $q['lazy_load_term_meta'],
    	)
    );

    Again this assumes $q is defined as referring to $wp_query->query_vars

    • This reply was modified 1 year, 11 months ago by Doug Wollison.
Viewing 1 replies (of 1 total)
  • The topic ‘retrieve_sticky_posts() not correctly checking post__not_in’ is closed to new replies.