Opened 11 years ago
Closed 9 months ago
#27088 closed enhancement (invalid)
Allow per-query filtering of post status objects
Reported by: | ericmann | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.8.1 |
Component: | Query | Keywords: | needs-patch needs-unit-tests |
Focuses: | performance | Cc: |
Description
There comes a time where queries need to pull in posts (or CPTs) that have a non-public post status. Unfortunately, there are no filters on get_post_status()
or get_post_status_object()
to allow this kind of atomic control within WP_Query::get_posts()
.
To rectify this, we should add (at a minimum) filters on:
get_post_status()
get_post_status_object()
Additionally, a filter within WP_Query::get_posts()
(on the return of get_post_status_object()
with the query passed along for context) will allow per-query filtering of the status object if it needs to be overridden for specific reasons.
Attachments (3)
Change History (11)
#1
follow-up:
↓ 3
@
11 years ago
This ticket focuses directly on a solution. I think it would be best to flush out the problem first. There definitely shouldn't be hooks in those functions due to their nature of needing to return exactly and consistently what the post status definition, or in the other case it's little more than a helper for the post_status post property.
Instead, you should be able to control what status Wp_Query thinks the post is, and/or manipulate or bypass those checks via a particular query variable, filter, or some such.
#2
@
11 years ago
query-filter.diff changes the return values of get_post_status()
and get_post_status_object()
from a string and an object, respectively, to an array.
#3
in reply to:
↑ 1
@
11 years ago
Replying to nacin:
Instead, you should be able to control what status Wp_Query thinks the post is, and/or manipulate or bypass those checks via a particular query variable, filter, or some such.
I can accept that. This is why the original patch introduced 3 different filters: 1 each for the post status functions, and 1 inside WP_Query::get_posts() itself.
Based on this feedback, perhaps only the third filter is appropriate.
#4
@
11 years ago
Two options that I see:
- The posts_results filter is sufficient to fake the status of a post, at least in all situations I can picture. the_posts is also a useful hook here. Use cases would be very helpful here.
- Or, something like 27088.diff, which I don't love but is closer to what makes sense to me.
#5
@
11 years ago
I ran into this yesterday, in fact :) Here's how I did it: show-scheduled-posts.php
Adding an additional filter to WP Query is a hack, in my opinion, that only addresses the immediate use case. The proper fix is to implement the first part of Nacin's suggestions in #12706. In doing so, we'd define the attributes of a post status, and the behaviors each attribute should exhibit.
Add 3 new filters to allow atomic control of post status objects.