Opened 2 years ago
Last modified 2 years ago
#17551 new enhancement
Need a post_id query that works regardless of post_type.
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Query | Version: | 3.2 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
The query parameter p works for posts and pages but not attachments. When the ID in question refers to an attachment, the result is a 404. Why?
When generating a stats report for a remote blog, the WordPress.com Stats/Jetpack system at first only knows the post_id of a new post. Eventually it learns the correct permalink by querying the blog, but until then its best guess at a working link is ?p=$post_id.
This problem (and possibly others) would be most easily solved by a core query parameter that can find any post_type by its ID alone. Unless there is a reason to limit p, I propose we make p work for all post_types. If there is a reason, how about a new public query parameter post_id?
Change History (5)
comment:3
in reply to:
↑ description
;
follow-ups:
↓ 4
↓ 5
solarissmoke — 2 years ago
Replying to andy:
The query parameter p works for posts and pages but not attachments. When the ID in question refers to an attachment, the result is a 404. Why?
But it doesn't issue a 404... it redirects to ?attachment_id=N
Replying to solarissmoke:
Replying to andy:
The query parameter p works for posts and pages but not attachments. When the ID in question refers to an attachment, the result is a 404. Why?
But it doesn't issue a 404... it redirects to ?attachment_id=N
Only when it's attached to a published post I believe.
I can't really see a need for a public query var here.. nor private (as you set post_type = any, post_status = any for that one). Perhaps wherever Stats is getting the post ID from, it should be passing a permalink too.. either that, or i'm completely mis-understanding the implementation..
Replying to nacin:
Is this something that can be done from a plugin?
Of course. Plugins are limited in power only by who writes them. I wondered whether p was this way by design or by accident. If by accident, we can fix it. If by design, we can design a new parameter. If core doesn't want that, I'll put it in the plugin.
Replying to solarissmoke:
But it doesn't issue a 404... it redirects to ?attachment_id=N
Compare http://ma.tt/?p=38232 and http://ma.tt/?attachment_id=38232. The parent post is published yet the 'p=' query produces a 404, not a redirect.

+1 for post_id, but it still wouldn't match attachments, since they have post_status=inherit.