Tagged: custom fields, masonry
Hi,
I recently updated Enfold to it’s latest version, and I’m trying to add custom fields values to the Captions part of the Masonry element. As of now it can display Title and Excerpt, and I would like to be able to display other custom fields I have created (in that case the text value that I called ‘speaker’), and also control styling for it.
It looks that since the last major update, it is managed in class-avia-masonry.php, and that there are also some filters that can be used.
I would really appreciate if someone could help me figure out the best, sustainable way, to use custom fields with Masonry.
Thanks,
Mat
Well, I have found a way to add the Custom Field to the Content part using get_post_meta & the name of my Custom Field (‘speaker’). If it can help anyone, or if anyone wants to give me input to improve it, please do :
/* Filter to add Custom Fields to Masonry Post list */
add_filter("avf_masonry_entry_content", function($content, $entry, $config) {
$speakers = get_post_meta( $entry["ID"], 'speaker', true);
$separator = ' ';
$output = '';
if ( ! empty( $speakers ) ) {
$output = '<b><em>' . esc_html( $speakers ) . '</b></em><br>';
$content = $output . $content;
}
return $content;
}, 10, 3);
Hi Twohandsbrands,
Thanks for showing the solution that worked for you :)
I think it’s an excellent solution that uses a hook.
Best regards,
Nikko