[wp-hackers] Retrieving post id based on the page title

Sudar Muthu sudar at sudarmuthu.com
Sat Sep 12 12:10:04 UTC 2009


Joost,

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,
Sudar

http://SudarMuthu.com
http://twitter.com/sudarmuthu


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?
>
> http://xref.yoast.com/2.8.4/nav.html?_functions/get_page_by_title.html
>
> Cheers,
> Joost
>
>
>
> 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.
>>
>> Thanks!
>>
>> With Regards,
>> Sudar
>>
>> http://SudarMuthu.com
>> http://twitter.com/sudarmuthu
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list