#16149 closed enhancement (maybelater)
Allow querying for the standard post format
Reported by: | nacin | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | Query | Keywords: | has-patch |
Focuses: | Cc: |
Description
So, you currently can't query the standard post format through /type/standard/. It's not actually a term that gets stored in the database, which made this a fun puzzle to solve over the last few hours. (Props Mark as well.)
The attached patch:
- Establishes a shell 'standard' term, to prevent us from faking too much more. This is enforced in set_post_format() to ensure it never goes far.
- Reroutes the 'standard' post format request to a tax_query that does a NOT IN for every other format. It plays as nice as possible by appending to an existing tax_query and simply forcing AND.
- Corrects the query flags and the queried object, ensuring proper template selection and such.
- Performs other black magic.
This is required for 1:1 support for people who used categories. The only side effect here is, well, that it doesn't work. It's very well contained.
This additionally fixes a bug:
For taxonomies, post_type is set to 'any'. We only want post_type = 'post' for formats -- or more accurately, any post type that has chosen to support formats. Anyone doing this will need to both add_post_type_support and register_taxonomy_for_object_type, and the latter is easily fetchable with $tax->object_type. Thus, post_type is set to that.
Attachments (2)
Change History (29)
#1
@
14 years ago
- Milestone changed from 3.1 to Future Release
- Type changed from defect (bug) to enhancement
#3
@
14 years ago
- Milestone changed from Future Release to 3.1
Moving back to 3.1 for the bug fix. Basically means doing:
$tax = get_taxonomy( 'post_format' ); $qvs['post_type'] = $tax->object_type;
Will follow along with a patch later.
#6
@
13 years ago
Thanks, that's just what I needed (saved me from hacking it together myself)! I drive an email newsletter via my RSS feed, but I only wanted it to pull standard blog posts. When I tried just using '.../type/standard', I was surprised that it didn't work as expected (or at all) out-of-the-box. Some implementation of this definitely need to go into core.
#7
@
13 years ago
I started hacking on this a little differently before realizing there was an existing ticket for this. Having now reviewed the existing patch, they are better than what I had come up with with one exception: these don't allow you to do a manual WP_Query by standard format:
$q = new WP_Query(array( 'post_format' => 'post-format-standard' ));
because they hook on 'request'.
I've hooked on 'pre_get_posts' instead, which will also handle manual queries - I think this is important functionality to include. Perhaps we need to hook in on 'parse_query' instead to use the approach in Nacin's patch?
Here is what I was hacking on, in case it is of interest.
https://gist.github.com/1549613
A big +1 from me on this functionality being desirable as a core feature.
#9
@
13 years ago
- Cc mikeschinkel@… added
Why the URL format /type/standard/
instead of /format/standard/
? Seems tremendously confusing given custom post types and post formats.
#10
@
13 years ago
We chose /type/
back in 3.1 as a default because "format" is a writing convention, but not a reading one. You don't expect people to read posts that have the "format" of images — they want to browse image posts. It's only confusing to developers, and they usually get over it. :-)
#14
@
12 years ago
- Milestone Future Release deleted
- Resolution set to maybelater
- Status changed from new to closed
Thinking we can leave this to a plugin for now. There hasn't been a lot of demand for this.
#16
@
11 years ago
I know we've closed this, but speaking to the demand...I got asked by two separate people at WordCamp San Diego about this. I think that as post formats come to the forefront this is going to become a bigger deal.
I seem to be the only one who cares about having access to a feed of standard posts. It can wait until 3.2. Although be warned, I may push for doing this right and having actual
post-status-standard
associations with posts. Would be less hacky than this solution!