Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#13943 closed defect (bug) (invalid)

Sticky posts are sticky posts even if they are trashed

Reported by: bi0xid Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: reporter-feedback, sticky posts
Focuses: Cc:


Hello there.

I have some problem with sticky posts.

I'm using this function to get the last of them:

	$sticky = get_option( 'sticky_posts' );
	echo '<strong><a href="'.get_permalink($sticky[0]).'">'.get_the_title($sticky[0]).'</a></strong>';
	echo '<a href="'.get_permalink($sticky[0]).'">'.get_the_post_thumbnail($sticky[0], 'thumbnail').'</a>'; 

I have trashed a sticky post, and this function still echoes the post in the trash.

If I delete it permanently it of course disappears.

Change History (4)

#1 @nacin
11 years ago

  • Milestone changed from 3.0 to Unassigned

When using WP_Query to query posts, sticky posts that are trashed will be excluded.

I suppose we could add a filter to get_option('sticky_posts') that excludes any trashed IDs, or better yet unstick any post when it is trashed, but I'm not sure if either of those would be what the expected behavior is.

The code you provide I imagine would work for any post in the trash, not just sticky ones.

#2 @dd32
11 years ago

I believe that code may even show "Draft Stickies".

I'd agree with that that option is not destined to be used that way.

IMO, you should only use it within a query, for example:

$posts = get_posts( array('post_status' => 'publish', 'post__in' => get_option( 'sticky_posts' ) ) );

#3 @bi0xid
11 years ago

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

Gotcha. Thanks :)

#4 @nacin
11 years ago

  • Milestone Unassigned deleted
Note: See TracTickets for help on using tickets.