Last active
January 10, 2019 19:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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