Skip to content

Instantly share code, notes, and snippets.

@jcpeden
Created June 7, 2012 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcpeden/2888847 to your computer and use it in GitHub Desktop.
Save jcpeden/2888847 to your computer and use it in GitHub Desktop.
BuddyPress Members List Based on Profile Field Match
//Load members list on research centre pages
//Build list of users based on research centre slug
function research_centre_member_function() {
global $post;
$ancs = get_ancestors($post->ID, 'page');
if(($ancs[1] == 128) || ($ancs[1] == 136) || ($ancs[1] == 138)) {
global $wpdb;
$slug = basename(get_permalink());
//Build array to match permalink slug to profile field value
$centre_array = array(
'Contemporary Fine Art and Critical Theory Research Centre' => 'contemporary-fine-art-and-critical-theory-research-centre',
'Autonomous Systems and Advanced Robotics Research Centre' => 'autonomous-systems-and-advanced-robotics-research-centre',
'Biomedical Research Centre' => 'biomedical-research-centre',
'CASE Control and Systems Engineering Research Centre' => 'case-control-and-systems-engineering-research-centre',
'Centre for Applied Archaeology' => 'centre-for-applied-archaeology',
'Centre for Democracy and Human Rights' => 'centre-for-democracy-and-human-rights',
'Centre for Disaster Resilience' => 'centre-for-disaster-resilience',
'Centre for English Literature and Language' => 'centre-for-english-literature-and-language',
'Centre for European Security' => 'centre-for-european-security',
'Centre for Health Sport and Rehabilitation Sciences Research' => 'centre-for-health-sport-and-rehabilitation-sciences-research',
'Centre for Information Systems Organisations and Society Research Centre' => 'centre-for-information-systems-organisations-and-society-research-centre',
'Centre for Linguistics and Applied Linguistics' => 'centre-for-linguistics-and-applied-linguistics',
'Centre for Nursing and Midwifery Research' => 'centre-for-nursing-and-midwifery-research',
'Centre for Property and Facilities Management' => 'centre-for-property-and-facilities-management',
'Centre for Social Justice Research' => 'centre-for-social-justice-research',
'Centre for Social Research' => 'centre-for-social-research',
'Centre for Sustainable Urban and Regional Futures' => 'centre-for-sustainable-urban-and-regional-futures',
'Centre for Translation and Interpreting' => 'centre-for-translation-and-interpreting',
'Civil Engineering Research Centre' => 'civil-engineering-research-centre',
'College of Health & Social Care' => 'college-of-health-&-social-care',
'College of Science & Technology' => 'college-of-science-&-technology',
'Communication Cultural and Media Studies' => 'communication-cultural-and-media-studies',
'Computer Networking and Telecommunications Research Centre' => 'computer-networking-and-telecommunications-research-centre',
'Construction Information Technology Research Centre' => 'construction-information-technology-research-centre',
'Contemporary Fine Art and Critical Theory Research Centre' => 'contemporary-fine-art-and-critical-theory-research-centre',
'Creative Technology and Communications Research Centre' => 'creative-technology-and-communications-research-centre',
'Data Mining and Pattern Recognition Research Centre' => 'data-mining-and-pattern-recognition-research-centre',
'Ecosystems and Environment Research Centre' => 'ecosystems-and-environment-research-centre',
'Enterprise and Innovation Research Centre' => 'enterprise-and-innovation-research-centre',
'Heritage and Design Innovation Research Centre' => 'heritage-and-design-innovation-research-centre',
'Management in Construction Research Centre' => 'management-in-construction-research-centre',
'Marketing and Strategy Research Centre' => 'marketing-and-strategy-research-centre',
'Materials and Physics Research Centre' => 'materials-and-physics-research-centre',
'Operations Management Management Science and Statistics' => 'operations-management-management-science-and-statistics',
'Organisational Behaviour and Leadership Research Centre' => 'organisational-behaviour-and-leadership-research-centre',
'Performance Research Centre' => 'performance-research-centre',
'Research Centre for Education in the Built Environment' => 'research-centre-for-education-in-the-built-environment',
'Salford Centre for Research and Innovation' => 'salford-centre-for-research-and-innovation',
'Salford Centre of Legal Research' => 'salford-centre-of-legal-research',
'Salford Centre of Music Research' => 'salford-centre-of-music-research',
'SURFACE Inclusive Design Research Centre' => 'surface-inclusive-design-research-centre',
'Urban Quality Research Centre' => 'urban-quality-research-centre',
'Virtual Environments and Future Media Research Centre' => 'virtual-environments-and-future-media-research-centre'
);
$centre_name = array_search($slug, $centre_array);
//Query db for member user ids
$db_query = "SELECT user_id FROM g5yew1jnkb_bp_xprofile_data WHERE field_id = 2 AND value = \"" .$centre_name ."\"";
$match_ids = $wpdb->get_var($db_query);
$get_these_members = 'include=' .$match_ids;
//Begin members loop
if (bp_has_members($get_these_members)) { ?>
<?php do_action( 'bp_before_directory_members_list' ) ?>
<ul id="members-list" class="item-list">
<?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>
<?php if ( bp_get_member_latest_update() ) : ?>
<span class="update"> - <?php bp_member_latest_update( 'length=10' ) ?></span>
<?php endif; ?>
</div>
<div class="item-meta"><span class="activity"><?php bp_member_last_active() ?></span></div>
<?php do_action( 'bp_directory_members_item' ) ?>
</div><div class="clear"></div>
</li>
<?php endwhile; ?>
</ul>
<?php do_action( 'bp_after_directory_members_list' ) ?>
<?php bp_member_hidden_fields() ?>
<?php } else { ?>
<div id="message" class="info">
<p><?php _e( "No users were found registered to this research centre.", 'buddypress' ) ?></p>
</div>
<?php }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment