Skip to content

Instantly share code, notes, and snippets.

@richardegil
Created December 4, 2012 20:01
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 richardegil/4208087 to your computer and use it in GitHub Desktop.
Save richardegil/4208087 to your computer and use it in GitHub Desktop.
Alpha names
// part 1
<?php
// needed to access data from cpt-onomies
global $cpt_onomy;
// grabs the current taxonomy data being used by this page.
$current_taxonomy = $wp_query->queried_object;
// grabs the data associated with the current taxonomy being used.
$term = $cpt_onomy->get_term_by( 'name', $current_taxonomy->post_title, 'specialties' );
// builds an object with the associated data, in this case all of the doctors associated with this specialty.
$objects = $cpt_onomy->get_objects_in_term( $term->term_id, 'specialties' );
// lists out each doc and pulls in the associated custom fields from the faculty profile.
$namearray = array();
$currentarray = array();
$i = 0;
foreach ($objects as $object) {
$page = get_post($object);
$custom_fields = get_post_custom($page->ID);
$mycurrentarray = $currentarray[$i];
$mycurrentarray['fname'] = $first_name = $custom_fields['_faculty_profile_information_faculty_fname'][0];
$middle_name = $custom_fields['_faculty_profile_information_faculty_mname'][0];
$mycurrentarray['mi'] = $middle_initial = substr($middle_name, 0, 1);
$mycurrentarray['lname'] = $last_name = $custom_fields['_faculty_profile_information_faculty_lname'][0];
$degrees_data = unserialize($custom_fields['_faculty_profile_information_faculty_degrees'][0]);
$mycurrentarray['degrees'] = $the_degrees = implode(", ", $degrees_data);
array_push($namearray, $mycurrentarray);
$i++;
}
usort($namearray, 'compare_lastname');
foreach ($namearray as $key => $value) {
//echo $value['fname'];
if ($value['mi'] != '') {
echo '<li><a href="'. get_permalink($page->ID) .'">' . $value['fname'] . ' ' . $value['mi'] . '. ' . $value['lname'] . ', ' . $value['degrees'] . '</a></li>';
} else {
echo '<li><a href="'. get_permalink($page->ID) .'">' . $value['fname'] . ' ' . $value['lname'] . ', ' . $value['degrees'] . '</a></li>';
}
}
?>
// part 2
function compare_lastname($a, $b)
{
return strnatcmp($a['lname'], $b['lname']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment