Skip to content
Permalink
13721f3115
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
185 lines (157 sloc) 5.28 KB
<?php
//
// Order search results by post_title
//
function my_search_query( $query ) {
// not an admin page and is the main query
if ( !is_admin() && $query->is_main_query() ) {
if ( is_search() ) {
$query->set( 'orderby', 'post_title' );
$query->set( 'order', 'ASC' );
}
}
}
add_action( 'pre_get_posts', 'my_search_query' );
function neag_scripts() {
wp_enqueue_style( 'neag-style', get_stylesheet_directory_uri() . '/css/neag.css');
wp_enqueue_script('neag-custom', get_stylesheet_directory_uri().'/js/custom.js', array('jquery', 'cs'));
wp_localize_script( 'neag-custom', 'neag_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'siteurl' => site_url() ) );
wp_enqueue_style( 'neag-print', get_stylesheet_directory_uri() .'/css/print.css', array( 'neag-style' ), false, 'print');
}
add_action( 'wp_enqueue_scripts', 'neag_scripts');
if ( function_exists('register_sidebar') ) {
register_sidebar( array(
'name' => __( 'Header - Social Media' ),
'id' => 'header',
'description' => __( 'Widgets in this area will be shown in the header.' ),
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer - Left' ),
'id' => 'footer-left',
'description' => __( 'Widgets in this area will be shown on the left hand side of the footer.' ),
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer - Center' ),
'id' => 'footer-center',
'description' => __( 'Widgets in this area will be shown on the right hand side of the footer.' ),
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer - Right' ),
'id' => 'footer-right',
'description' => __( 'Widgets in this area will be shown on the right hand side of the footer.' ),
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
}
function neag_sort_by_last_then_first( $a, $b ){ // a and b are people IDs
setlocale(LC_CTYPE, 'en_US.UTF8'); // Using setlocale and iconv incase a name has an accent or other similar characters in them
$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;
}
function processPosts( $queryPosts, $expertsFlag = false ){
usort( $queryPosts, 'neag_sort_by_last_then_first' );
$fields = array( 'first_name' => '', 'middle_name' => '', 'last_name' => '', 'title' => '', 'email' => '', 'phone' => '', 'office_location' => '', 'expertise' => '' );
$alphabet = array_fill_keys( range('A', 'Z'), '' );
$people = array();
foreach( $queryPosts as $i=>$id ){
$people[$i] = array();
foreach( $fields as $k=>$v ){
$fields[$k] = get_field( $k, $id );
}
$people[$i]['name'] = "{$fields['first_name']} {$fields['middle_name']} {$fields['last_name']}";
$people[$i]['permalink'] = get_permalink( $id );
$people[$i]['phone'] = $fields['phone'];
$people[$i]['title'] = $fields['title'];
$people[$i]['email'] = $fields['email'];
$people[$i]['office_location'] = $fields['office_location'];
$people[$i]['photo'] = get_the_post_thumbnail( $id, array(115, 115) );
$people[$i]['expertise'] = $fields['expertise'];
$nameLetter = $fields['last_name'][0]; // $fields['last_name'] is a string
$setDivIDFlag = false;
if( empty( $alphabet[$nameLetter] ) ){
$setDivIDFlag = true;
$alphabet[$nameLetter] = true;
}
if( $setDivIDFlag == true ){
$people[$i]['divid'] = $nameLetter;
} else {
$people[$i]['divid'] = '';
}
}
return $people;
}
add_action( 'wp_ajax_neag_get_people', 'neag_get_people_callback' );
add_action( 'wp_ajax_nopriv_neag_get_people', 'neag_get_people_callback' );
function neag_get_people_callback(){
$categoryID = $_POST['categoryID'];
$args = array(
'post_type' => array( 'person' ),
'fields' => 'ids',
'posts_per_page' => -1,
);
if( $categoryID != 0 ){
$termSearch = array();
$termSearch['taxonomy'] = 'group';
$termSearch['field'] = 'term_id';
$termSearch['terms'] = $categoryID;
$taxQuery = array( $termSearch );
$args['tax_query'] = $taxQuery;
}
$query = new WP_Query( $args );
$queryPosts = $query->posts;
$people = array();
if( $query->have_posts() ){
$people = processPosts( $queryPosts );
}
echo wp_json_encode( $people );
wp_die();
}
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_person_neag',
'title' => 'Person',
'fields' => array (
array (
'key' => 'field_expertise',
'label' => 'Faculty Area of Expertise',
'name' => 'expertise',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'person',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
}
?>