Developers can be a stubborn lot. We like to focus on the things we know really well, and things we don’t deal with as often can be seen as “hard”. Search is one of those things that gets written off a lot, few devs I know will deal with it (voluntarily), and almost everyone will tell you “WordPress search sucks.” In this presentation you will learn that not only do you know more about how search works than you thought you did, but maybe give you a better understanding of how WordPress works as a whole, as well as showing you some cool tricks that you can do with WordPress search.
15. 3 misconceptions
about search
3.“WordPress search sucks.”
Does what you ask it to.
No weight given to titles vs. content.
16. 3 misconceptions
about search
3.“WordPress search sucks.”
Does what you ask it to.
No weight given to titles vs. content.
You can do a lot of cool stuff with
search…
17. 3 misconceptions
about search
3.“WordPress search sucks.”
Does what you ask it to.
No weight given to titles vs. content.
You can do a lot of cool stuff with
search…
(if you know how)
56. <?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; ?>
57. /**
* 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();
$do_not_duplicate[] = $post->ID; // add this post to the duplicate array so we don't get duplicates
58. /**
* 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' );
59. /**
* 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' );
http://s3q.us/
wcslc2014-cs-search
66. Where does that
leave us?
“I don’t know anything about search.”
You do now.
67. Where does that
leave us?
“I don’t know anything about search.”
You do now.
“WordPress search is hard.”
Not any more so than normal queries.
68. Where does that
leave us?
“I don’t know anything about search.”
You do now.
“WordPress search is hard.”
Not any more so than normal queries.
“WordPress search sucks.”
No, it doesn’t.