Make WordPress Core

Opened 22 months ago

Last modified 22 months ago

#49550 new defect (bug)

is_home is set to true even for cron jobs, which causes sticky posts to get prepended to all WP_Query results

Reported by: archon810 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3.2
Component: Query Keywords:
Focuses: Cc:



We just ran into a bug where sticky posts were prepended to the list of posts being processed by a WP cron job in a new WP_Query like this:

$query = new WP_Query([
        'post_status' => 'future',
        'date_query' => array(
            'before' => '- 1 minute'
        'numberposts' => -1

To my surprise, once someone stickied a post, our function in the cron job started doing stuff to the stickied posts, even though it simply runs in WP cron and we're not on the homepage.

I then looked at the logic that determines if the sticky posts get prepended.

// Put sticky posts at the top of the posts array
$sticky_posts = get_option( 'sticky_posts' );
if ( $this->is_home && $page <= 1 && is_array( $sticky_posts ) && ! empty( $sticky_posts ) && ! $q['ignore_sticky_posts'] ) {

So this can only fire when is_home is true. But how can it be? We're running via WP cron.

Looking at that logic:

if ( ! ( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots ) ) {
    $this->is_home = true;

Since none of these are set - we're in WP cron - is_home gets set to true. That doesn't seem right. Is this a sneaky bug or am I missing something? Shouldn't it also check if it's running in cron here and not set is_home if so?

Change History (1)

#1 @SergeyBiryukov
22 months ago

  • Component changed from General to Query
Note: See TracTickets for help on using tickets.