WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#11072 closed defect (bug) (fixed)

Honor Post Type for Sticky Posts

Reported by: chrisscott Owned by: ryan
Milestone: 2.9 Priority: normal
Severity: normal Version:
Component: Query Keywords: has-patch needs-testing
Focuses: Cc:

Description

When specifying a post type in WP_Query, sticky posts are added to the beginning of the array regardless of the post_type if specified. The attached patch will restrict the stickies to match the post_type if specified. This is compatible with the multiple post types patch submitted in #10791.

Attachments (1)

query.php.diff (1.1 KB) - added by chrisscott 4 years ago.

Download all attachments as: .zip

Change History (7)

chrisscott4 years ago

comment:1 scribu4 years ago

  • Milestone changed from Unassigned to 2.9

comment:2 scribu4 years ago

  • Keywords changed from has-patch, needs-testing to has-patch needs-testing

comment:3 tott4 years ago

The solution looks fine to me but I think the query should run to $wpdb->prepare first.

comment:4 ryan4 years ago

This will break stickies for regular queries since the post_type is not set for them:

SELECT * FROM wp_posts WHERE wp_posts.ID IN (1611) AND wp_posts.post_type IN ('')

We'll need to set it further up or maybe use the post_type_cap.

comment:5 ryan4 years ago

prepare() doesn't get along with IN() queries. I think it'll be fine as is since post_type is sanitized.

comment:6 ryan4 years ago

  • Resolution set to fixed
  • Status changed from new to closed

[12143]

I added an empty string check to get it working.

Note: See TracTickets for help on using tickets.