// Add Custom Fields | |
add_action ('genesis_entry_content', 'rp_painting' ); | |
function rp_painting() { | |
if ( ! ( is_single() ) ) { | |
return; | |
} | |
// These are the custom field keys defined in the dashboard: | |
$metas_painting = array( | |
'painting-image', | |
'painting-alt-text', | |
'painting-video', | |
'painting-archive-image', | |
'painting-medium', | |
'painting-signed', | |
'painting-size', | |
'painting-year', | |
'painting-price', | |
); | |
// If _any_ ACF field is filled in, it's a go. | |
$has_meta = false; // init | |
foreach ($metas_painting as $test ) { | |
if ( get_field($test) ) { | |
$has_meta = true; | |
continue; // Just need one meta field filled to create the div. | |
} | |
} | |
if ( $has_meta ) { | |
echo '<div class="custom-data painting-custom-data">'; | |
echo '<h2>Painting Details:</h2>'; | |
foreach ( $metas_painting as $meta_painting ) { | |
$$meta_painting = get_field($meta_painting); | |
if ( $$meta_painting ) { | |
$f_object = get_field_object($meta_painting); | |
$label = $f_object['label']; | |
echo '<div class="' . $meta_painting . '">' . | |
'<span class="label">' . $label . ':</span> ' . | |
'<span class="value">' . $$meta_painting . '</span>' . | |
'</div>'; | |
} | |
} | |
echo '</div><!-- /.custom-data -->'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment