Skip to content

Instantly share code, notes, and snippets.

@jazzsequence jazzsequence/cs_search.php Secret
Created Sep 1, 2014

Embed
What would you like to do?
curated sound search page
<?php
/**
* If users exist, deal with displaying them first
*/
if ( curated_have_users() && curated_show_users() ) :
// get the classes to display user results
$classes = curated_get_grid_classes( $i, 4 ); ?>
<div id="user-<?php echo sanitize_title( get_search_query() ); ?>" class="tile-wrap <?php echo esc_attr( $classes ); ?> ">
<?php get_template_part( 'partials/search', 'user' ); ?>
</div>
<?php
// increment $i
$i++;
endif; ?>
<?php
/**
* set up an array of arguments to determine post2post relationships
* this stuff gets set up too late to be used in pre_get_posts so
* I have to use query_posts.
*/
$search_term = curated_posts_like_title( get_search_query() );
$query_args = array(
'connected_type' => 'songs_to_artists',
'connected_items' => $search_term,
'connected_direction' => 'any',
'nopaging' => true,
// make sure this post isn't a duplicate
'post__not_in' => $do_not_duplicate
);
if ( curated_has_connected_posts( $search_term ) ) {
// only run the query posts if we need it
query_posts( $query_args );
// sometimes query_posts will break and return nothing even if something should be returned. If this happens, reset the query and move on
if ( !have_posts() ) {
wp_reset_query();
}
}
while ( have_posts() ) : the_post();
// add this post to the duplicate array so we don't get duplicates
$do_not_duplicate[] = $post->ID;
?>
<?php
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
// don't display the other results if we are only looking at users
if ( 'user' != curated_get_search_selected() && 'artist' != get_post_type() ) {
if ( '' == $classes ) {
// if classes haven't been set yet, setup the classes
$classes = curated_get_grid_classes( $i, 4 );
} ?>
<div id="<?php echo get_post_type(); ?>-<?php echo $post->ID; ?>" class="tile-wrap <?php echo get_post_type(); ?> <?php echo esc_attr( $classes ); ?>">
<?php get_template_part( 'partials/search', get_post_type() ); ?>
</div>
<?php }
wp_reset_query();
$i++; // increment the counter again
endwhile;
curated_paging_nav();
else :
get_template_part( 'content', 'none' );
endif;
?>
@jazzsequence

This comment has been minimized.

Copy link
Owner Author

commented Jan 16, 2015

This gist shows the searchform that this is the search page for https://gist.github.com/jazzsequence/0ed45d2b08275427dc00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.