Skip to content

Instantly share code, notes, and snippets.

@marktenney
Created July 6, 2023 16:13
Show Gist options
  • Save marktenney/857825303b9b1bacefbfd386091feb4c to your computer and use it in GitHub Desktop.
Save marktenney/857825303b9b1bacefbfd386091feb4c to your computer and use it in GitHub Desktop.
<?php
function cornerstone_group_leaders_shortcode() {
global $post;
$post_id = $post->ID;
// Retrieve the leader post IDs for the current post ID
$leader_ids = get_post_meta( $post_id, 'leaders', true );
// Generate the output
$output = '';
if ( ! empty( $leader_ids ) ) {
$output .= '<ul>';
foreach ( (array) $leader_ids as $leader_id ) {
$leader_name = get_the_title( $leader_id );
if ( $leader_name ) {
$output .= '<li>' . esc_html( $leader_name ) . '</li>';
}
}
$output .= '</ul>';
} else {
$output .= '<div class="admin-visible">No group leaders found for this post.</div>';
}
return $output;
}
add_shortcode( 'cornerstone-group-leaders', 'cornerstone_group_leaders_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment