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

Jeremy Clarke jer at simianuprising.com
Mon Feb 22 16:31:38 UTC 2010


As stated above the most basic (and probably the most efficient way)
would be to do a get_post($id) then check the status and type
properties to make sure they are what you want, in which case you'd
already have a nice post object to use.

Alternately if you wanted just one call to check you could use
get_posts() and include arguments for the properties you want to
check. In this case 'publish' status and 'post' type are the defaults,
so if there are any results then the ID exists. I don't feel like
digging into the source, but I think get_post() will probably be
faster though, as it will only check one row in the DB.

-- 
Jeremy Clarke | http://jeremyclarke.org
Code and Design | http://globalvoicesonline.org


More information about the wp-hackers mailing list