Opened 9 years ago
Closed 9 years ago
#33921 closed defect (bug) (worksforme)
Twenty Fourteen: Featured_Content::get_sticky_posts() not checking post_status
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.8 |
Component: | Bundled Theme | Keywords: | 2nd-opinion |
Focuses: | Cc: |
Description
As the method static method Featured_Content::get_sticky_posts()
only gets the sticky_post IDs from wp_options table, but does not check that the post_status is equal to publish.
My suggestion would be:
/** * Return an array with IDs of posts marked as sticky. * * @static * @access public * @since Twenty Fourteen 1.0 * * @return array Array of published sticky posts. */ public static function get_sticky_posts() { $args = array( 'fields' => 'ids', 'numberposts' => self::$max_posts, 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => false, 'post__in' => get_option( 'sticky_posts' , array()), ); $sticky_post_ids = get_posts( $args ); return $sticky_post_ids; }
Change History (6)
#2
in reply to:
↑ 1
@
9 years ago
Thanks Sergey,
Your observation is right.
I did not describe the problem properly. The test case for me was that I had a limit set to fetch five IDs by Featured_Content::get_sticky_posts() and all of the IDs were drafts. No featured posts were returned, because the method did not get to those IDs that had a post_status equal to publish.
Bottom line I was expecting five featured posts, but got none.
Replying to SergeyBiryukov:
Hi @stode, welcome to Trac!
I could not reproduce the issue. My steps:
- Create a draft sticky post.
- Make sure I don't have a
featured
tag.- Clear the
'featured_content_ids'
transient in the database.- The featured content section displays published sticky posts, but not the draft post.
Featured_Content::get_sticky_posts() indeed just returns the value of
'sticky_posts'
option without any further checking.
However, when Featured_Content::get_featured_posts() calls
get_posts()
later, the implicit defaultpost_status
value is applied, which is publish.
#3
@
9 years ago
- Keywords reporter-feedback removed
- Summary changed from Twenty Fourteen: Featured_Content::get_sticky_posts() getting also non published posts to Twenty Fourteen: Featured_Content::get_sticky_posts() not checking post_status
I would ask that, do you @SergeyBiryukov, think that this is a too much of an edge case or a relevent addition to the method to check for post_status?
Hi @stode, welcome to Trac!
I could not reproduce the issue. My steps:
featured
tag.'featured_content_ids'
transient in the database.Featured_Content::get_sticky_posts() indeed just returns the value of
'sticky_posts'
option without any further checking.However, when Featured_Content::get_featured_posts() calls
get_posts()
later, the implicit defaultpost_status
value is applied, which is publish.