Skip to content

Instantly share code, notes, and snippets.

@Mamaduka
Created April 14, 2015 14:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mamaduka/e7725a9b789c2386a676 to your computer and use it in GitHub Desktop.
Save Mamaduka/e7725a9b789c2386a676 to your computer and use it in GitHub Desktop.
<?php
/**
* Handle Team shortcode.
*
* @param array $attr Array of shortcode attributes.
* @return string $output HTML
*/
function maintainn_team_shortcode( $attr = array() ) {
// Get post object.
$post = get_post();
// Get team members attached to this page.
$members = get_post_meta( $post->ID, '_maintainn_team_meta', true );
$output = '';
// Return empty string, if we don't have members.
if ( empty( $members ) ) {
return $output;
}
// We have team members and now we can output them.
$output .= '<ul class="maintainn-team">';
foreach ( $members as $member ) {
$output .= '<li class="member">';
$output .= '<img src="' . esc_attr( $member['photo'] ) . '" alt="' . esc_attr( $member['fullname'] ) . '" />';
$output .= '<h3 class="fullname">' . esc_attr( $member['fullname'] ) . '</h3>';
$output .= '<p class="position">' . esc_attr( $member['position'] ) . '</p>';
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
add_shortcode( 'maintainn_team', 'maintainn_team_shortcode' );
@ulaulaman
Copy link

Excuse me if I comment this code, but I'm a bit perplexed.
I create a group field (here) that it seems similar to your group and so I used your code with my fields in order to create a shortcode (here) but it don't works, and I don't understand why the shortcode didn't print the field values!?
Any suggestions, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment