Support Forum
Support › Meta Box Group › if ( ! empty ) returning blank fields rather than else content
Some of my fields are returning blank values rather than reading the fields as empty, so rather than my 'else' argument (No coverage found) I'm just getting white space and my CSS border.
I have a sneaking suspicion this is happening on posts that USED to have content in those fields, but whose content has since been deleted. Deleting the text doesn't seem to clear the field entirely.
Any suggestions?
// Event Coverage
$coveragegroup = rwmb_meta( 'cf_coverage' );
if ( ! empty( $coveragegroup ) ) {
echo '<div class="eventcoverage">';
echo '<div class="coverage">';
echo '<ul>';
// Call Coverage Data
foreach ( $coveragegroup as $coveragedata ) {
echo '<li>';
echo '<a href="' . $coveragedata['cf_coverageurl'] . '" target=_blank>' . $coveragedata['cf_coveragedesc'] . '</a><br>';
// Coverage Date
$thecoveragedate = $coveragedata['cf_coveragedate'];
if ( ! empty( $thecoveragedate ) ) {
$thecoveragedate = $coveragedata['cf_coveragedate'];
$getcoveragedate = date( 'jS F Y', strtotime($thecoveragedate) );
echo '<div class="coveragedate">';
echo $getcoveragedate;
echo '</div>';
}
echo '</li>';
}
echo '</div></div>';
}
else {
echo '<p>No coverage found</p>';
}
echo '</ul>';
Just noticed I had that UL in the wrong place, but still having the same problem:
// Event Coverage
$coveragegroup = rwmb_meta( 'cf_coverage' );
if ( ! empty( $coveragegroup ) ) {
echo '<div class="eventcoverage">';
echo '<div class="coverage">';
echo '<ul>';
// Call Coverage Data
foreach ( $coveragegroup as $coveragedata ) {
echo '<li>';
echo '<a href="' . $coveragedata['cf_coverageurl'] . '" target=_blank>' . $coveragedata['cf_coveragedesc'] . '</a><br>';
// Coverage Date
$thecoveragedate = $coveragedata['cf_coveragedate'];
if ( ! empty( $thecoveragedate ) ) {
$thecoveragedate = $coveragedata['cf_coveragedate'];
$getcoveragedate = date( 'jS F Y', strtotime($thecoveragedate) );
echo '<div class="coveragedate">';
echo $getcoveragedate;
echo '</div>';
}
echo '</li>';
}
echo '</ul>';
echo '</div></div>';
}
else {
echo '<p>No coverage found</p>';
}
Which version of the Meta Box and Group are you using? There were some problems of the plugin and group which made them didn't save the value correctly. Can you please update to the latest version and see if it's resolved?
If it's not, can you please post the code you setup the fields? Thanks.
Meta Box 4.7
Meta Box Group 1.0.2
function cf_events_register_meta_boxes( $meta_boxes )
{
$prefix = 'cf_';
//Coverage
$meta_boxes[] = array(
'title' => 'Event Coverage',
'post_types' => 'events',
'context' => 'normal',
'priority' => 'low',
'desc' => '(drag to reorder)',
'fields' => array(
array(
'id' => 'cf_coverage',
'type' => 'group',
'clone' => true,
'sort_clone' => true,
'fields' => array(
array(
'name' => 'Title',
'id' => $prefix . 'coveragedesc',
'type' => 'text',
'desc' => 'Title or description for link',
),
array(
'name' => 'URL',
'id' => $prefix . 'coverageurl',
'type' => 'text',
'desc' => 'Link to coverage',
),
array(
'name' => 'Date',
'id' => $prefix . 'coveragedate',
'type' => 'date',
'desc' => 'Date of event coverage',
),
),
),
),
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'cf_events_register_meta_boxes' );
I see. Can you please update the Meta Box to 4.7.2 and Group to 1.0.3? The 1.0.3 version of Group has a fix for this.