Make WordPress Core

Opened 3 years ago

Closed 22 months ago

Last modified 8 days ago

#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:


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)

16149.diff (2.7 KB) - added by nacin 3 years ago.
query-standard-format-posts.php (2.2 KB) - added by markjaquith 3 years ago.
Plugin to enable querying of standard format posts.

Download all attachments as: .zip

Change History (24)

nacin3 years ago

comment:1 markjaquith3 years ago

  • Milestone changed from 3.1 to Future Release
  • Type changed from defect (bug) to enhancement

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!

markjaquith3 years ago

Plugin to enable querying of standard format posts.

comment:2 markjaquith3 years ago

There — that's the same thing in plugin form, to hold people over.

comment:3 nacin3 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.

comment:4 automattor3 years ago

(In [17249]) Limit post format queries to the post types registered for the taxonomy. see #16149.

comment:5 nacin3 years ago

  • Milestone changed from 3.1 to Future Release

comment:6 dougal3 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.

comment:7 alexkingorg2 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.


A big +1 from me on this functionality being desirable as a core feature.

comment:8 alexkingorg2 years ago

  • Cc alexkingorg@… added

comment:9 mikeschinkel2 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.

comment:10 nacin2 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. :-)

comment:11 DrewAPicture2 years ago

  • Cc xoodrew@… added

comment:12 wpsmith2 years ago

  • Cc travis@… added

comment:13 mbijon22 months ago

  • Cc mike@… added

comment:14 nacin22 months 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.

comment:15 carstenbach19 months ago

  • Cc carstenbach added

comment:16 aaroncampbell13 months 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.

comment:17 wonderboymusic13 months ago

^ totally agree

comment:18 dpcalhoun10 months ago

I'd like to see this in core as well. I'd argue there is demand with post formats becoming more prominent in themes.

comment:19 tollmanz9 months ago

  • Cc tollmanz@… added


comment:20 beaulebens7 months ago

  • Cc beau@… added

comment:21 kraftbj5 months ago

  • Cc bk@… added
Note: See TracTickets for help on using tickets.