Created
July 6, 2023 16:13
-
-
Save marktenney/857825303b9b1bacefbfd386091feb4c to your computer and use it in GitHub Desktop.
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 | |
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