Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to check if post meta key exists or not, out side of the loop. Is there any WordPress function to check if post meta key exist or not in WordPress database. I have to check this outside the loop. Any help will be highly appreciated.

share|improve this question
    
possible duplicate of Strategy to get post meta for use outside the loop –  Brian Fegter Jul 25 '12 at 10:03
add comment

1 Answer

You could use get_post_custom(POST ID GOES HERE) which will return a multidimensional array with all custom fields of a particular post or page.

So something like:

$meta_data = get_post_custom(785);
if ($meta_data['my_meta_key'][0] != "")
    ...

would allow you check if a particular meta_key was empty or not.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.