Skip to content

Instantly share code, notes, and snippets.

@konradsroka
Created April 28, 2016 18:14
Show Gist options
  • Save konradsroka/e40222e357456f11e18a0f5182bacd8d to your computer and use it in GitHub Desktop.
Save konradsroka/e40222e357456f11e18a0f5182bacd8d to your computer and use it in GitHub Desktop.
<?php
// display member list filtered by profile fields
function member_list_by_profile_fields( $atts ) {
global $bp, $wpdb;
$atts = shortcode_atts( array(
'id' => '1',
'YOURFIELDNAME' => 'default-value' // this can be just a number! check in bp profile field settings with inspector tool ;)
), $atts, 'member_list_by_profile_fields' );
ob_start(); ?>
<?php if ( bp_has_members( array( 'search_terms' => $atts['YOURFIELDNAME'] ) ) ) : ?>
<ul id="members-list" class="item-list" role="main">
<?php while ( bp_members() ) : bp_the_member(); ?>
<li>
<div class="item-avatar">
<a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
</div>
<div class="item">
<div class="item-title">
<a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>
</div>
<div class="item-meta"><span class="activity"><?php bp_member_last_active(); ?></span></div>
</div>
<div class="clear"></div>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<div id="pag-bottom" class="pagination">
<div class="pag-count" id="member-dir-count-bottom">
<?php bp_members_pagination_count(); ?>
</div>
<div class="pagination-links" id="member-dir-pag-bottom">
<?php bp_members_pagination_links(); ?>
</div>
</div>
<?php $render = ob_get_contents();
ob_end_clean();
return $render;
}
add_shortcode('member_list_by_profile_fields', 'member_list_by_profile_fields');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment