#12727 closed enhancement (duplicate)
Allow get_post*() and get_page*() functions to query by more than ID or using an post object.
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Post Types | Version: | 3.0 |
| Severity: | normal | Keywords: | |
| Cc: | mikeschinkel@… |
Description
This is similar to ticket #12726 which I just submitted but is broader. There are many functions in post.php (and probably elsewhere) that accept a $post as a lookup parameter where $post is either an ID or an object with an attribute of "ID" containing a post ID, i.e. $post->ID. It would be nice if they could optionally accept other lookup criteria such as 'path' and 'title.'
It could be something like this:
$post = get_post(new WP_PostBy('path','mypath'));
class WP_PostBy {
var $field;
var $value;
function __construct($field,$value) {
$this->field = $field;
$this->value = $value;
}
}
Or it could be just as simple as a two element array, i.e.
$post = get_post(array('path','mypath'));
I'll be happy to do the coding if the task is 'blessed' and any special cases that I need to handle are identified.
Change History (7)
comment:2
in reply to:
↑ 1
mikeschinkel — 3 years ago
- Cc mikeschinkel@… added
Replying to nacin:
We have a get_user_by() function. Emulating that for pages/posts/post_types I think is what you're trying to get at with this ticket and #12726. Sounds like a good idea in theory, though strong doubts on 3.0 for it.
Cool. Wasn't really expecting it for 3.0, just wanted to get it into the queue... :-)
comment:3
mikeschinkel — 3 years ago
- Keywords posts post types removed
- Keywords 2nd-opinion removed
- Milestone Unassigned deleted
- Resolution set to duplicate
- Status changed from new to closed
Fixed in #12743. Nice job sneaking that one in :-)

We have a get_user_by() function. Emulating that for pages/posts/post_types I think is what you're trying to get at with this ticket and #12726. Sounds like a good idea in theory, though strong doubts on 3.0 for it.