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

John Blackbourn johnbillion+wp at gmail.com
Mon Feb 22 02:55:41 UTC 2010


wp_is_post_revision() and wp_is_post_revision() will probably help.

On Sun, Feb 21, 2010 at 11:45 PM, Hikari <lists at hikarinet.info> wrote:
> 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,
> etc)
>
> 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
> http://Hikari.ws
> http://ConscienciaPlanetaria.com
>
> 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".
> |
>
> _______________________________________________
> 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