Skip to content

Instantly share code, notes, and snippets.

@MikeRawlins
Last active May 10, 2016 16:15
Show Gist options
  • Save MikeRawlins/be609a976b7044310ea1272001145d15 to your computer and use it in GitHub Desktop.
Save MikeRawlins/be609a976b7044310ea1272001145d15 to your computer and use it in GitHub Desktop.
// 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