alleyinteractive / wp-alleyvate

Defaults for WordPress sites by Alley.
GNU General Public License v2.0
18 stars 2 forks source link

[FEATURE]: Disable sticky posts #41

Closed mboynes closed 1 year ago

mboynes commented 1 year ago

Description

Sticky Posts is a feature of WordPress to allow users to "stick" posts to the front page. It's almost like curation, but the user doesn't have control over their order.

Use Case

As far as I'm aware, we've never built around or advised that our clients use this feature, but yet it's present in the admin and if a client actually used it, it could potentially cause significant issues. To illustrate this, simply mark an old post as sticky (not the most recent post), then hop into wp shell and run $q = new WP_Query( [ 'posts_per_page' => 1 ] );. One would expect this query to contain one post, the most recent one. But, because of sticky posts, it contains two ($q->post_count should confirm this), with the first post being the sticky one and the second post being the most recent. You could even use post__in to make this even more baffling, e.g. $q = new WP_Query( [ 'post__in' => [ 1178 ] ] ); gives me 2 posts in my demo site 😧.

You can imagine the consequences here if on this site we ran a query in the sidebar for latest posts, we had a couple of queries in the supernav, etc. -- the sticky post could well be the first post in all of these places! WP_Query has an argument ignore_sticky_posts which would prevent this behavior, but it's easy to forget to add this to all custom queries.

High-level, the solution to this should both remove the UI for sticky posts (in classic and gootz) and disable the functionality. Sticky posts are stored in an option, so a potential solution would be to short circuit this option so it always returns an empty value, even if there actually are historical sticky posts in the database.

renatonascalves commented 1 year ago

it's easy to forget to add this to all custom queries.

Is adding a custom rule for the Alley Coding Standards worth adding?