Forums
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I am using a custom meta box to post a description however, it outputs
when there is no content. How can I write an if statement so if there is content, it will post, otherwise output nothing?
// usually needed
global $custom_metabox;
// get value directly
$custom_metabox->the_value('description');
?>
Try this
global $custom_metabox;
if (($value = $custom_metabox->the_value('description')) !== '') {
echo '' . $value . '
';
}
?>
@SgtLegend It still outputs
See what the output value is by using the following as it sounds like white space may be present in the value.
echo 'Value: ' . $custom_metabox->the_value('description');
@SgtLegend That outputs the following
Value:
Sorry, forgot to wrap it in a function.
echo 'Value: ' . strlen($custom_metabox->the_value('description'));
Value: 0
@ChrisxClash, Ah I think that worked but how would I incorporate:
@ChrisxClas Exactly although it’s not working.
@ChrisxClash Nothing. It just outputs the text without the markup
@ChrisxClash Correct.
Try this instead:
$desc = $custom_metabox->the_value('description');
if (!empty($desc)): ?>
".$desc.""; ?>
@AntonNiklasson That didn’t work either, unfortunately.
If the one that Chis posted isn’t outputting the markup then I have a feeling like you’re updating the wrong file. Or perhaps your server is caching.
@ChrisxClash, @Jamy_za tried helping me out to no success at this time. I sent him my entire theme and what I’m using for my custom meta box (WPAlchemy).
@TheDoc, I thought it was my cache also but I completely cleared it several times.