update_post_meta()
calls update_metadata
which begins with this line:
if ( !$meta_type || !$meta_key )
return false;
I wrote a simple test (with a lot of cut & paste) to see how string values of 0 are evaluated (instead of looking it up in the PHP manual):
<?php
$meta_key = (string) 0;
if ( ! $meta_key )
echo "0 exits function<br />";
else {
echo "0 remains in function<br />";
echo " \$meta_key = $meta_key<br />";
echo " (integer) \$meta_key = " . (integer) $meta_key . '<br />';
}
echo '<br />';
$meta_key = (string) 0;
if ( ! $meta_key )
echo "(string) 0 exits function<br />";
else {
echo "(string) 0 remains in function<br />";
echo " \$meta_key = $meta_key<br />";
echo " (integer) \$meta_key = " . (integer) $meta_key . '<br />';
}
echo '<br />';
$meta_key = (string) '0';
if ( ! $meta_key )
echo "(string) '0' exits function<br />";
else {
echo "(string) '0' remains in function<br />";
echo " \$meta_key = $meta_key<br />";
echo " (integer) \$meta_key = " . (integer) $meta_key . '<br />';
}
echo '<br />';
$meta_key = 0x0;
if ( ! $meta_key )
echo "0x0 exits function<br />";
else {
echo "0x0 remains in function<br />";
echo " \$meta_key = $meta_key<br />";
echo " (integer) \$meta_key = " . (integer) $meta_key . '<br />';
}
echo '<br />';
$meta_key = (string) 0x0;
if ( ! $meta_key )
echo "(string) 0x0 exits function<br />";
else {
echo "(string) 0x0 remains in function<br />";
echo " \$meta_key = $meta_key<br />";
echo " (integer) \$meta_key = " . (integer) $meta_key . '<br />';
}
echo '<br />';
$meta_key = '0x0';
if ( ! $meta_key )
echo "'0x0' exits function<br />";
else {
echo "'0x0' remains in function<br />";
echo " \$meta_key = $meta_key<br />";
echo " (integer) \$meta_key = " . (integer) $meta_key . '<br />';
}
echo '<br />';
$meta_key = (string) '0x0';
if ( ! $meta_key )
echo "(string) '0x0' exits function<br />";
else {
echo "(string) '0x0' remains in function<br />";
echo " \$meta_key = $meta_key<br />";
echo " (integer) \$meta_key = " . (integer) $meta_key . '<br />';
}
The result was:
0 exits function
(string) 0 exits function
(string) '0' exits function
0x0 exits function
(string) 0x0 exits function
'0x0' remains in function
$meta_key = 0x0
(integer) $meta_key = 0
(string) '0x0' remains in function
$meta_key = 0x0
(integer) $meta_key = 0
So, to add a value of 0 you could change it to the string '0x0' and cast it to integer when retrieving it. 0x0 is binary (I think) for 0.
0
will resolve tofalse
under some circumstances. That may be part of the problem, but as @vancoder has requested, we need more code.