Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active January 10, 2019 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/a6cff51ed56276641c4d4ea0a82b25b9 to your computer and use it in GitHub Desktop.
Save cliffordp/a6cff51ed56276641c4d4ea0a82b25b9 to your computer and use it in GitHub Desktop.
The Events Calendar: Display WordPress custom fields in the Item Details part of the List Venues Organizers Shortcode extension.
<?php
/**
* The Events Calendar: Display WordPress custom fields in the Item Details part of the
* List Venues Organizers Shortcode extension.
*
* Excludes hidden fields (beginning with `_`) and Elegant Theme's hidden fields (beginning with `et_`).
* Authored by Richard of memberwise.org.uk and Clifford (Tribe Support).
*
* @link https://gist.github.com/cliffordp/a6cff51ed56276641c4d4ea0a82b25b9 This snippet.
* @link https://theeventscalendar.com/extensions/list-venues-and-organizers-shortcodes/ Extends this extension.
*
* @param string $item_details
* @param int $post_id
*
* @return string
*/
function tribe_ext_list_venues_organizers_show_wp_custom_fields( $item_details, $post_id ) {
foreach ( get_post_meta( $post_id ) as $field => $value ) {
$field = trim( $field );
if ( is_array( $value ) ) {
$value = implode( ', ', $value );
}
// Exclude hidden fields
if (
0 === strpos( $field, '_' )
|| 0 === strpos( $field, 'et_' )
) {
continue;
}
$value = esc_html( $value );
if ( '' === $value ) {
continue;
}
$item_details .= sprintf( '<strong class="%s">%s</strong>%s<br/>', esc_attr( $field ), $value, PHP_EOL );
}
return $item_details;
}
add_filter( 'tribe_ext_list_venues_organizers_shortcodes_item_details', 'tribe_ext_list_venues_organizers_show_wp_custom_fields', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment