';
+ $people = $the_query->get_posts();
+ usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') );
+
+ foreach( $people as $id ){
+ $out .= '
';
$out .= '
';
}
$person_count++;
- } //end of while posts
+ }
$out .= '
'; // div.row
} else {
@@ -69,18 +71,31 @@ Class UC_People_Widget extends WP_Widget {
return $out;
}
- private function createTextCell( $field, $information_to_display ){
+ private static function sort_by_last_then_first($a,$b) {
+ setlocale(LC_CTYPE, 'en_US.UTF8');
+ $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $b)) );
+ if( $r === 0 ){
+ $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $b)) );
+ }
+ return $r;
+ }
+
+ private function createTextCell( $field, $information_to_display, $id ){
$cell = '';
if (in_array($field, $information_to_display)) {
- $cell .= '
'.get_field($field).' | ';
+ $cell .= '
'.get_field($field, $id ).' | ';
}
return $cell;
}
private function get_people_table( $args, $information_to_display ){
$the_query = new WP_Query( $args );
+
$out = '';
if ( $the_query->have_posts() ) {
+ $people = $the_query->get_posts();
+ usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') );
+
// how many columns? Based on what they chose to display.
$num_cols = count($information_to_display);
@@ -106,41 +121,39 @@ Class UC_People_Widget extends WP_Widget {
$out .= '';
$out .= '
';
- while ( $the_query->have_posts() ) {
- $the_query->the_post();
-
- $out .= '';
- if (in_array('photo', $information_to_display)) {
- $out .= ''.the_post_thumbnail(array('65', '65')).' | ';
- }
- if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){
- $out .= '';
- if (in_array('first_name', $information_to_display)) {
- $out .= get_field('first_name');
- $out .= ' ';
- };
- if (in_array('middle_name', $information_to_display)) {
- $out .= get_field('middle_name');
- $out .= ' ';
- };
- if (in_array('last_name', $information_to_display)) {
- $out .= get_field('last_name');
- };
- $out .= ' | ';
- }
+ foreach( $people as $id ){
+ $out .= '
';
+ if (in_array('photo', $information_to_display)) {
+ $out .= ''.get_the_post_thumbnail($id, array('65', '65')).' | ';
+ }
+ if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){
+ $out .= '';
+ if (in_array('first_name', $information_to_display)) {
+ $out .= get_field('first_name', $id );
+ $out .= ' ';
+ };
+ if (in_array('middle_name', $information_to_display)) {
+ $out .= get_field('middle_name', $id );
+ $out .= ' ';
+ };
+ if (in_array('last_name', $information_to_display)) {
+ $out .= get_field('last_name', $id );
+ };
+ $out .= ' | ';
+ }
- foreach( $this->fields as $f ){
- if( $f == 'file' && in_array('file', $information_to_display) ){
- $file = get_field('file');
- $out .= ''.$file[title].'';
- } else if( $f == 'email' && in_array('email', $information_to_display) ){
- $out .= ' | '.get_field('email').' | ';
- } else {
- $out .= $this->createTextCell($f, $information_to_display);
- }
+ foreach( $this->fields as $f ){
+ if( $f == 'file' && in_array('file', $information_to_display) ){
+ $file = get_field('file', $id );
+ $out .= ''.$file[title].'';
+ } else if( $f == 'email' && in_array('email', $information_to_display) ){
+ $out .= ' | '.get_field('email', $id ).' | ';
+ } else {
+ $out .= $this->createTextCell($f, $information_to_display, $id );
}
- $out .= '
';
- } //end of posts
+ }
+ $out .= '';
+ }
$out .= '';
$out .= '';
} else {
@@ -158,9 +171,11 @@ Class UC_People_Widget extends WP_Widget {
$wpQueryArgs = array(
'posts_per_page' => -1,
'post_type' => 'person',
- 'orderby' => 'menu_order title',
- 'order' => 'ASC',
- 'post__in' => ( ( !is_null($settings['specific_people']) ) ? $settings['specific_people'] : array() )
+ //'orderby' => 'menu_order title',
+ //'order' => 'ASC',
+ //'order' => 'post__in',
+ 'post__in' => ( ( !is_null($settings['specific_people']) ) ? $settings['specific_people'] : array() ),
+ 'fields' => 'ids'
);
if ( $settings['specific_groups'] != false || $settings['specific_tags'] != false ){
diff --git a/uc-people.php b/uc-people.php
index e86d172..072c914 100644
--- a/uc-people.php
+++ b/uc-people.php
@@ -34,7 +34,9 @@ function create_custom_custom_post_type(){
'menu_icon' => 'dashicons-groups',
'supports' => array( 'tags', 'thumbnail', 'revisions', 'page-attributes', 'author' ),
'has_archive' => true,
- 'rewrite' => false
+ 'rewrite' => array(
+ 'slug' => '/person'
+ )
);
register_post_type( 'person', $args );