[wp-trac] [WordPress Trac] #39965: REST API: not possible to request collection of posts across post types
WordPress Trac
noreply at wordpress.org
Wed Jul 26 15:15:37 UTC 2017
#39965: REST API: not possible to request collection of posts across post types
-------------------------+-----------------------
Reporter: iseulde | Owner: jnylen0
Type: enhancement | Status: assigned
Priority: normal | Milestone: 4.9
Component: REST API | Version: 4.7
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------+-----------------------
Comment (by danielbachhuber):
Replying to [comment:6 jnylen0]:
> While it's true that `/wp/v2/posts` currently means "posts with
`post_type` of `post`", at least a post of another type is still a post.
This is an incorrect assumption that will likely lead to negative
downstream implications. In the context of the database schema, yes
different content types are stored in the same table (and history shows
some of the ramifications of that).
In the context of the REST API data model, not all posts are alike — in
fact, they can be more different than similar.
Is a `nav_item` a type of post? Is a WooCommerce `product` a type of post?
Both are shaped drastically different than a standard WordPress `post`.
Any client code trying to handle arbitrarily shaped data is going to be a
mess.
Furthermore, I believe trying to fit a `type` argument into
`WP_Posts_Controller` would be a pretty substantial monkey-patch
development job. Currently, a request to `/wp/v2/posts` follows a
different code path than a request to `/wp/v2/pages`. You'd need to hack
around the PHP architecture to get the controllers to behave consistently.
And so on.
> How about a separate endpoint like `/wp/v2/posts/all_types`?
This seems like a hack to me. If there's one specific feature of Gutenberg
for this use-case, then I'd suggest Gutenberg handle this entirely and
leave the API as it is.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39965#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list