[wp-hackers] Retrieving post id based on the page title
sudar at sudarmuthu.com
Thu Sep 17 17:36:07 UTC 2009
Okay, at last I had time to digg a little deeper into the code.
For a revision, the post_type is set to revision and not to post/page as I
thought earlier. So this code will work fine and sorry for the confusion. :)
On Sat, Sep 12, 2009 at 17:40, Sudar Muthu <sudar at sudarmuthu.com> wrote:
> Thanks for pointing out this function. (I missed it when I looked into
> WordPress code)
> I had a quick look into the function and it is using the following query
> SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='page'",
> $page_title )
> If post revisions is enabled, and there is a auto-save version available
> will it not get the id of the revision post row rather than the one which
> was published?
> My gut feeling says that we should also include the condition post_status =
> 'published'. Am I correct or am I missing something?
> (I will do some test to find out whether my theory works!)
> With Regards,
> On Sat, Sep 12, 2009 at 17:29, Joost de Valk <joost at yoast.com> wrote:
>> There's a get_page_by_title, modify it to use with posts, in fact, it
>> should probably be modified within core?
>> On Sep 12, 2009, at 1:55 PM, Sudar Muthu wrote:
>> Hello all,
>>> I need to know if there is a built-in function (or recommended way) to
>>> retrieve the post id of a page/post based on the post title, without
>>> querying the database directly.
>>> I know it can be done by querying the database, but I prefer to use the
>>> build-in function if available. A quick look into WordPress code, didn't
>>> reveal any function.
>>> With Regards,
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
More information about the wp-hackers