Created
September 5, 2011 22:03
-
-
Save curtismchale/1196025 to your computer and use it in GitHub Desktop.
Takes the results of a search query and runs a bunch of filters on it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function tan_athlete_search_page(){ | |
if( isset($_GET['sport']) ) { | |
$sport = $_GET['sport']; | |
$sportquery = array( 'key' => 'sfn_tan_choose_sport', 'compare' => 'like', 'value' => $sport ); | |
} else { | |
$sportquery = ''; | |
} | |
if( !empty($_GET['state']) ) { | |
$state = $_GET['state'];} else { } | |
if( !empty($_GET['grad']) ) { | |
$grad = $_GET['grad'];} else { } | |
if( isset($_GET['fbposition']) ) { | |
$fbposition = $_GET['fbposition']; | |
$positionquery = array( 'key' => 'sfn_tan_football_position', 'compare' => 'like', 'value' => $fbposition ); | |
} else { $positionquery = ''; } | |
if( isset($_GET['post_type']) ){ | |
$cpt = $_GET['post_type']; | |
$cptvalue = array( 'athlete_profile', 'academic_profile'); | |
} else { | |
$cptvalue = array( 'post', 'page' ); | |
} | |
$searchResults = new WP_Query( array( | |
'post_type' => $cptvalue, | |
'meta_query' => array( | |
$sportquery, $positionquery, | |
), | |
)); | |
?> | |
<?php if ( $searchResults->have_posts() ) : | |
$posts = $searchResults->posts; | |
// sfn_print_r( $posts ); | |
// passing all results in to an array of authors | |
$authorids = array(); | |
foreach( $posts as $post ){ | |
$authorids[] = $post->post_author; | |
} | |
// removing duplicate author ids from the array | |
$authorids = array_unique( $authorids ); | |
// sfn_print_r( $authorids ); | |
// checks state against author | |
if( empty($state) ) { | |
// do nothing b/c we're not filtering by state | |
} else { | |
$authorByState = array(); | |
$removeAuthorByState = array(); | |
foreach( $authorids as $authorid ){ | |
$author = $authorid; | |
if( $state == get_the_author_meta( 'state', $author ) ) { | |
$authorbystate[] = $authorid; | |
} else { | |
$removeAuthorByState[] = $authorid; | |
} | |
} | |
$authorids = $authorbystate; | |
// sfn_print_r( $authorbystate ); | |
} // ends check for state | |
// check for graduation year | |
if( !empty($grad) ){ | |
$authorGrad = array(); | |
$authorNotGrad = array(); | |
foreach( $authorids as $authorid ) { | |
$academicPosts = get_posts( 'post_type=academic_profile&author='.$authorid ); | |
if( get_post_meta( $academicPosts['0']->ID, 'sfn_tan_hs_graduation_year', true ) == $grad ) { | |
$authorGrad[] = $authorid; | |
} else { | |
$authorNotGrad[] = $authorid; | |
} | |
} | |
$authorids = $authorGrad; | |
} | |
foreach( $authorids as $authorid ){ | |
$author = $authorid; | |
show_athlete_profile_image( $author, 100, 100 ); | |
show_athlete_profile_information( $author, 'publish' ); | |
echo '<div class="clear"></div>'; | |
} | |
?> | |
<!-- post content goes here --> | |
<?php else: ?> | |
<h3>Oops!! Looks like something went wrong. Please get in touch with the site <a href="mailto:<?php echo get_bloginfo('admin_email'); ?>">administrator</a> and we'll get this sorted out</h3> | |
<?php endif; ?> | |
<?php wp_reset_query(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment