Make WordPress Core

Opened 13 years ago

Closed 12 years ago

Last modified 8 years ago

#16149 closed enhancement (maybelater)

Allow querying for the standard post format

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

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

Download all attachments as: .zip

Change History (29)

@nacin
13 years ago

#1 @markjaquith
13 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!

@markjaquith
13 years ago

Plugin to enable querying of standard format posts.

#2 @markjaquith
13 years ago

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

#3 @nacin
13 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.

#4 @automattor
13 years ago

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

#5 @nacin
13 years ago

  • Milestone changed from 3.1 to Future Release

#6 @dougal
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 @alexkingorg
12 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.

#8 @alexkingorg
12 years ago

  • Cc alexkingorg@… added

#9 @mikeschinkel
12 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 @nacin
12 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. :-)

#11 @DrewAPicture
12 years ago

  • Cc xoodrew@… added

#12 @wpsmith
12 years ago

  • Cc travis@… added

#13 @mbijon
12 years ago

  • Cc mike@… added

#14 @nacin
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.

#15 @carstenbach
11 years ago

  • Cc carstenbach added

#16 @aaroncampbell
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.

#17 @wonderboymusic
11 years ago

^ totally agree

#18 @dpcalhoun
11 years 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.

#19 @tollmanz
11 years ago

  • Cc tollmanz@… added

+1

#20 @beaulebens
11 years ago

  • Cc beau@… added

#21 @kraftbj
10 years ago

  • Cc bk@… added

#24 @nacin
9 years ago

#27054 was marked as a duplicate.

#27 @danfoy
8 years ago

The patch plugin is great, but I've noticed that it doesn't work with Jetpack Infinite Scroll - the first page works as expected, but all subsequent pages include posts from all formats.

I'm hiding these with CSS currently, but this seems pretty ineficient.

Note: See TracTickets for help on using tickets.