[wp-hackers] Best way to verify if a post_id is valid

Hikari lists at hikarinet.info
Sun Feb 21 23:45:54 UTC 2010

tnx for the reply

what I want is basically know if that ID refers to a post that exists and can be accesses

it will be used to get the post permalink and title, and if it's an invalid ID the function should return an error

by "invalid" I mean, beyond an ID that is not in database, also "posts" that are revisions, or weren't published yet (draft, trash, 

if that ID has a post that can be accesses by a URL, I want its pernalink, else I wanna return an error

get_post() is what I'm doing now, more precisely get_post($value, ARRAY_A), so I'm in the right way

thanks to Google I found http://codex.wordpress.org/Post_Status_Transitions, but I wasn't able to find the difference from draft to 
pending to new status

Hikari -  A Luz ilumina a PAZ

Tenha seu próprio email meunome @ ConscienciaPlanetaria.com.br!: http://seunome.ConscienciaPlanetaria.com.br

----- Original Message ----- 
From: "scribu" <scribu at gmail.com>
To: <wp-hackers at lists.automattic.com>
Sent: Sunday, 21 February, 2010 10:54 AM
Subject: Re: [wp-hackers] Best way to verify if a post_id is valid

| Maybe something like:
| if ( $post = get_post($post_id) && 'post' == $post->post_type && 'publish'
| == $post->post_status) {
|    // do stuff
| }
| Of course, it depends on what you're doing. So, there's no universal "best
| way".

More information about the wp-hackers mailing list