• Hi,

    I’d like to check for 0 meta value in post_meta table. I’m trying something like this but no luck so far:

    $meta_values = get_post_meta($post->ID, $meta_key, $single = true);
                    foreach($meta_values as $value){
                        if( $value==0){
                            $num_ratings++;
                        }
                        }

    Reason for this is that I only need to count number of non 0 meta_value records per post ID per given meta_key.

Viewing 2 replies - 1 through 2 (of 2 total)
  • setting $single to true returns the value as a string, not an array

    $meta_values = get_post_meta($post->ID, 'keyname', false);

    will return as array.

    You should also check meta_values after the fact with is_array()

    if (is_array($meta_values)) {

    Thread Starter hitcher

    (@hitcher)

    thank you got it sorted. it was custom post type $meta_key problem.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_post_meta to check for 0 meta value’ is closed to new replies.