get_post_meta – return values

What returns get_post_meta and what to check.

If you don’t look at the documentation, sometimes you think that it can return falseif there is no such field in the record. But no, it returns an empty string:

Because of this, it should only be checked for emptyotherwise the checks will fail.

So it will be correct:

$ related = get_post_meta($ postId, $ metaKey, true);

if (empty($ related)) {
die();
}

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *