Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#12727 closed enhancement (duplicate)

Allow get_post*() and get_page*() functions to query by more than ID or using an post object.

Reported by: mikeschinkel's profile mikeschinkel Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Posts, Post Types Keywords:
Focuses: Cc:

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)

#1 follow-up: @nacin
15 years ago

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.

#2 in reply to: ↑ 1 @mikeschinkel
15 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... :-)

#3 @mikeschinkel
15 years ago

  • Keywords posts post types removed

#4 @nacin
15 years ago

  • Keywords 2nd-opinion added

#5 follow-up: @nacin
15 years ago

  • 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 :-)

#6 @nacin
15 years ago

#12726 for get_post_by()

#7 in reply to: ↑ 5 @mikeschinkel
15 years ago

Replying to nacin:

Fixed in #12743. Nice job sneaking that one in :-)

I'm confused. What did I sneak in? (wasn't intentional...)

Note: See TracTickets for help on using tickets.