I've created a very complex custom post type system for a football website and am using custom meta boxes to store various match stats. To decide whether or not I should display a stat I check whether the data has been entered in the back end like this:
if (get_post_meta($post->ID, 'stat_red_h', true) || get_post_meta($post->ID, 'stat_red_a', true)){
echo 'somestuff';
}
Where I echo the information within the if statement. However, in many cases the value for a stat is "0" and if "0" is entered for both the home and away stat then the row doesn't show, presumably because it counts it as empty.
How can I tell WordPress that entering "0" as a value does not count it as empty, but is a valid value? Perhaps some sort of:
if ($stat_red_h=='0') {
$stat_red_h='REAL!!!';
}
In the functions file when saving the data? Perhaps you guys can help, this is the first time I've gone this deep into WordPress so I'm learning all the time.
Thanks, Mike
==
compares values;===
compares values and types. So if you're storing your values as strings (I think that's the default forupdate_post_meta()
), you should be able to do something likeif ( $stat_red_h === '0' ) { do_something; }
.