Make WordPress Core

Opened 11 years ago

Closed 9 months ago

#27088 closed enhancement (invalid)

Allow per-query filtering of post status objects

Reported by: ericmann's profile 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)

query-filter.diff (1.7 KB) - added by ericmann 11 years ago.
Add 3 new filters to allow atomic control of post status objects.
27088.diff (1.7 KB) - added by nacin 11 years ago.
show-scheduled-posts.php (763 bytes) - added by danielbachhuber 11 years ago.
Show scheduled posts on view

Download all attachments as: .zip

Change History (11)

@ericmann
11 years ago

Add 3 new filters to allow atomic control of post status objects.

#1 follow-up: @nacin
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 @SergeyBiryukov
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 @ericmann
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.

@nacin
11 years ago

#4 @nacin
11 years ago

Two options that I see:

  1. 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.
  1. Or, something like 27088.diff, which I don't love but is closer to what makes sense to me.

@danielbachhuber
11 years ago

Show scheduled posts on view

#5 @danielbachhuber
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.

#6 @wonderboymusic
11 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

Let's try to flesh this out or close it

#7 @chriscct7
9 years ago

  • Focuses performance added

#8 @pbearne
9 months ago

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

get_post_status() now has a filter so closing as invalid

Note: See TracTickets for help on using tickets.