SlideShare ist ein Scribd-Unternehmen logo
1 von 74
Why Hacking WordPress 
Search Isn’t Some Big 
Scary Thing 
WordCamp SLC 2014 
Chris Reynolds 
@jazzs3quence
Who’s 
this guy?
Who’s 
this guy? 
WordPress Developer
Who’s 
this guy? 
WordPress Developer
Who’s 
this guy? 
WordPress Developer
Who’s 
this guy? 
WordPress Developer 
Course Author
3 misconceptions 
about search
3 misconceptions 
about search 
1.“I don’t know anything about 
search.”
3 misconceptions 
about search 
1.“I don’t know anything about 
search.” 
?s=some%20query
3 misconceptions 
about search
3 misconceptions 
about search 
2.“WordPress search is hard.”
3 misconceptions 
about search
3 misconceptions 
about search 
3.“WordPress search sucks.”
3 misconceptions 
about search 
3.“WordPress search sucks.” 
Does what you ask it to.
3 misconceptions 
about search 
3.“WordPress search sucks.” 
Does what you ask it to. 
No weight given to titles vs. content.
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…
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)
What does WordPress 
search do? 
?s=your%20search
What does WordPress 
search do? 
?s=your%20search
What does WordPress 
search do? 
?s=your%20search 
( $wpdb->posts.post_title LIKE %s ) OR 
( $wpdb->posts.post_content LIKE %s )
Let me tell you 
something about 
query strings and 
the WordPress Loop
Recognize this? 
?p=123
What’s going 
on? 
?p=123
What about 
this? 
?cat=music
What’s going 
on? 
?cat=music
Did you know you 
can combine these? 
?post_type=article&cat=music
What’s going 
on? 
?post_type=article& 
taxonomy=music&term=jazz
-?p=123
-?p=123 
-?paged=2
-?p=123 
-?paged=2 
-?cat=music
-?p=123 
-?paged=2 
-?cat=music 
-?s=your%20search
$args = array( 
'post_type' => 'music', 
'paged' => $paged, 
'orderby' => 'date', 
'order' => 'DESC', 
'post_status' => 'publish', 
'ignore_sticky_posts' => 1 
); 
! 
$my_query = new WP_Query( $args ); 
! 
if ( $my_query->have_posts() ) : 
while ( $my_query->have_posts() ) : 
the_post();
$my_query = new 
WP_Query( 'post_type=music&post_stat 
us=publish&orderby=date&order=DESC&p 
aged=' . $paged . 
'&ignore_sticky_posts=1'); 
! 
if ( $my_query->have_posts() ) : 
while ( $my_query->have_posts() ) : 
the_post();
domain.com/? 
post_type=music&post_status=publish& 
orderby=date&order=DESC&paged=2&igno 
re_sticky_posts=1
WordPress search 
isn’t hard
WordPress search 
isn’t hard 
You already know all this stuff
WordPress search 
isn’t hard 
You already know all this stuff 
You just may not know you know it
Ready to have your mind 
blown?
Ready to have your mind 
blown? 
You can add all these query args to search
?s=your 
%20search&post_type=article&taxonomy=music 
&term=jazz
?s=your 
%20search&post_type=article&taxonomy=music 
&term=jazz
How do I actually 
use this? Like, in 
a form?
<form role="search" method="get" class="search-form" 
action="' . get_home_url( '/' ) . '"> 
<label> 
<input type="search" class="search-field" 
placeholder="Search" value="" name="s" 
title="Search for:" /> 
</label> 
<input type="hidden" name="music" value="jazz" /> 
<input type="hidden" name="post_type" value="article" 
/> 
</form>
<form role="search" method="get" class="search-form" 
action="' . get_home_url( '/' ) . '"> 
<label> 
<input type="search" class="search-field" 
placeholder="Search" value="" name="s" 
title="Search for:" /> 
</label> 
<input type="hidden" name="music" value="jazz" /> 
<input type="hidden" name="post_type" value="article" 
/> 
</form>
Examples!
posts
users posts
users songs posts
users songs posts 
?s=patrick&post_type%5B%5D=post&post_type%5B 
%5D=song&post_type%5B%5D=artist
<?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; ?>
/** 
* 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
/** 
* 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' );
/** 
* 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
only search within current taxonomy
function nps_get_taxonomy_search_form( $term = null, $taxonomy = null ) { 
! 
if ( !$term ) { 
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
$term = $term->name; 
} 
! 
if ( !$taxonomy ) 
$taxonomy = get_query_var( 'taxonomy' ); 
! 
$form =' 
<form role="search" method="get" class="search-form" action="' . get_home_url( '/' ) . '"> 
<label> 
<input type="search" class="search-field" placeholder="Search" value="" name="s" 
title="Search for:" /> 
</label> 
<input type="hidden" name="' . $taxonomy . '" value="' . $term . '" /> 
</form> 
'; 
! 
echo $form; 
}
function nps_get_taxonomy_search_form( $term = null, $taxonomy = null ) { 
! 
if ( !$term ) { 
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
$term = $term->name; 
} 
! 
if ( !$taxonomy ) 
$taxonomy = get_query_var( 'taxonomy' ); 
! 
$form =' 
<form role="search" method="get" class="search-form" action="' . get_home_url( '/' ) . '"> 
<label> 
<input type="search" class="search-field" placeholder="Search" value="" name="s" 
title="Search for:" /> 
</label> 
<input type="hidden" name="' . $taxonomy . '" value="' . $term . '" /> 
</form> 
'; 
! 
echo $form; 
} 
http://s3q.us/wcslc2014- 
nps-searchform
Where does that 
leave us?
Where does that 
leave us? 
“I don’t know anything about search.” 
You do now.
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.
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.
Questions?
Questions? 
Chris Reynolds 
@jazzs3quence
Questions? 
Chris Reynolds 
@jazzs3quence 
Pluralsight Courses — http://s3q.us/cr-ps
Questions? 
Chris Reynolds 
@jazzs3quence 
Pluralsight Courses — http://s3q.us/cr-ps 
These slides — http://s3q.us/wcslc2014
Questions? 
Chris Reynolds 
@jazzs3quence 
Pluralsight Courses — http://s3q.us/cr-ps 
These slides — http://s3q.us/wcslc2014 
Search form gist — http://s3q.us/wcslc2014-nps-searchform
Questions? 
Chris Reynolds 
@jazzs3quence 
Pluralsight Courses — http://s3q.us/cr-ps 
These slides — http://s3q.us/wcslc2014 
Search form gist — http://s3q.us/wcslc2014-nps-searchform 
Search page gist — http://s3q.us/wcslc2014-cs-search

Weitere ähnliche Inhalte

Was ist angesagt?

WordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPWordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPandrewnacin
 
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and ProfitOlaf Alders
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Karsten Dambekalns
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From IusethisMarcus Ramberg
 
FamilySearch Reference Client
FamilySearch Reference ClientFamilySearch Reference Client
FamilySearch Reference ClientDallan Quass
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created itPaul Bearne
 
WordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know queryWordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know queryl3rady
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodJeremy Kendall
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helperslicejack
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Php code for online quiz
Php code for online quizPhp code for online quiz
Php code for online quizhnyb1002
 

Was ist angesagt? (20)

WordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPWordPress 3.1 at DC PHP
WordPress 3.1 at DC PHP
 
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
Wsomdp
WsomdpWsomdp
Wsomdp
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Sk.php
Sk.phpSk.php
Sk.php
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
FamilySearch Reference Client
FamilySearch Reference ClientFamilySearch Reference Client
FamilySearch Reference Client
 
wget.pl
wget.plwget.pl
wget.pl
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
Inc
IncInc
Inc
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
WordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know queryWordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know query
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helper
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Php code for online quiz
Php code for online quizPhp code for online quiz
Php code for online quiz
 
DBI
DBIDBI
DBI
 

Andere mochten auch

Post and page in word press
Post and page in word pressPost and page in word press
Post and page in word pressLucky Ali
 
Mastering Custom Post Types - WordCamp Atlanta 2012
Mastering Custom Post Types - WordCamp Atlanta 2012Mastering Custom Post Types - WordCamp Atlanta 2012
Mastering Custom Post Types - WordCamp Atlanta 2012Mike Schinkel
 
WordPress theme setting page
WordPress theme setting pageWordPress theme setting page
WordPress theme setting pageNaeem Junejo
 
Relationships Between WordPress Post Types
Relationships Between WordPress Post TypesRelationships Between WordPress Post Types
Relationships Between WordPress Post Typesrandyhoyt
 
WordPress & Custm Post Types
WordPress & Custm Post TypesWordPress & Custm Post Types
WordPress & Custm Post TypesDinis Correia
 
WordPress 3 Custom Post Types
WordPress 3 Custom Post TypesWordPress 3 Custom Post Types
WordPress 3 Custom Post TypesDave Zille
 
WordPress Webinar Training Presentation
WordPress Webinar Training PresentationWordPress Webinar Training Presentation
WordPress Webinar Training PresentationMayeCreate Design
 

Andere mochten auch (7)

Post and page in word press
Post and page in word pressPost and page in word press
Post and page in word press
 
Mastering Custom Post Types - WordCamp Atlanta 2012
Mastering Custom Post Types - WordCamp Atlanta 2012Mastering Custom Post Types - WordCamp Atlanta 2012
Mastering Custom Post Types - WordCamp Atlanta 2012
 
WordPress theme setting page
WordPress theme setting pageWordPress theme setting page
WordPress theme setting page
 
Relationships Between WordPress Post Types
Relationships Between WordPress Post TypesRelationships Between WordPress Post Types
Relationships Between WordPress Post Types
 
WordPress & Custm Post Types
WordPress & Custm Post TypesWordPress & Custm Post Types
WordPress & Custm Post Types
 
WordPress 3 Custom Post Types
WordPress 3 Custom Post TypesWordPress 3 Custom Post Types
WordPress 3 Custom Post Types
 
WordPress Webinar Training Presentation
WordPress Webinar Training PresentationWordPress Webinar Training Presentation
WordPress Webinar Training Presentation
 

Ähnlich wie Why Hacking WordPress Search Isn't Some Big Scary Thing

You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix itRafael Dohms
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConRafael Dohms
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11Michelangelo van Dam
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmdiKlaus
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 
Beyond Posts & Pages - Structured Content in WordPress
Beyond Posts & Pages - Structured Content in WordPressBeyond Posts & Pages - Structured Content in WordPress
Beyond Posts & Pages - Structured Content in WordPressJohn Eckman
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in OptimizationDavid Golden
 
Your code sucks, let's fix it - PHP Master Series 2012
Your code sucks, let's fix it - PHP Master Series 2012Your code sucks, let's fix it - PHP Master Series 2012
Your code sucks, let's fix it - PHP Master Series 2012Rafael Dohms
 
Can WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.noCan WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.noMorten Rand-Hendriksen
 
You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011andrewnacin
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix itRafael Dohms
 

Ähnlich wie Why Hacking WordPress Search Isn't Some Big Scary Thing (20)

Php
PhpPhp
Php
 
Wp query
Wp queryWp query
Wp query
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Lithium Best
Lithium Best Lithium Best
Lithium Best
 
Victoria wordpress
Victoria wordpressVictoria wordpress
Victoria wordpress
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Intro to The PHP SPL
Intro to The PHP SPLIntro to The PHP SPL
Intro to The PHP SPL
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
OOP in PHP.pptx
OOP in PHP.pptxOOP in PHP.pptx
OOP in PHP.pptx
 
Beyond Posts & Pages - Structured Content in WordPress
Beyond Posts & Pages - Structured Content in WordPressBeyond Posts & Pages - Structured Content in WordPress
Beyond Posts & Pages - Structured Content in WordPress
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Your code sucks, let's fix it - PHP Master Series 2012
Your code sucks, let's fix it - PHP Master Series 2012Your code sucks, let's fix it - PHP Master Series 2012
Your code sucks, let's fix it - PHP Master Series 2012
 
Can WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.noCan WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.no
 
You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011
 
21. CodeIgniter search
21. CodeIgniter search21. CodeIgniter search
21. CodeIgniter search
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 

Mehr von Chris Reynolds

Developing an SDK for Personalization at the Edge
Developing an SDK for Personalization at the EdgeDeveloping an SDK for Personalization at the Edge
Developing an SDK for Personalization at the EdgeChris Reynolds
 
Outcomes vs Outputs: How Outcome Driven Development Planning Changes Everything
Outcomes vs Outputs: How Outcome Driven Development Planning Changes EverythingOutcomes vs Outputs: How Outcome Driven Development Planning Changes Everything
Outcomes vs Outputs: How Outcome Driven Development Planning Changes EverythingChris Reynolds
 
How the WordPress Block Editor Changes the Conversation for Content Editors a...
How the WordPress Block Editor Changes the Conversation for Content Editors a...How the WordPress Block Editor Changes the Conversation for Content Editors a...
How the WordPress Block Editor Changes the Conversation for Content Editors a...Chris Reynolds
 
How the WordPress Block Editor Changes the Conversation for Content Editors a...
How the WordPress Block Editor Changes the Conversation for Content Editors a...How the WordPress Block Editor Changes the Conversation for Content Editors a...
How the WordPress Block Editor Changes the Conversation for Content Editors a...Chris Reynolds
 
Who's afraid of the big bad loop?
Who's afraid of the big bad loop?Who's afraid of the big bad loop?
Who's afraid of the big bad loop?Chris Reynolds
 
Drop Kick Imposter Syndrome
Drop Kick Imposter SyndromeDrop Kick Imposter Syndrome
Drop Kick Imposter SyndromeChris Reynolds
 
Awesome Git Workflow for Agencies and Teams
Awesome Git Workflow for Agencies and TeamsAwesome Git Workflow for Agencies and Teams
Awesome Git Workflow for Agencies and TeamsChris Reynolds
 
9 Things You Didn't Know You Could Do with Your Blog WPSLC
9 Things You Didn't Know You Could Do with Your Blog WPSLC9 Things You Didn't Know You Could Do with Your Blog WPSLC
9 Things You Didn't Know You Could Do with Your Blog WPSLCChris Reynolds
 
9 things you didn't know you could do with your blog
9 things you didn't know you could do with your blog9 things you didn't know you could do with your blog
9 things you didn't know you could do with your blogChris Reynolds
 

Mehr von Chris Reynolds (10)

Developing an SDK for Personalization at the Edge
Developing an SDK for Personalization at the EdgeDeveloping an SDK for Personalization at the Edge
Developing an SDK for Personalization at the Edge
 
Outcomes vs Outputs: How Outcome Driven Development Planning Changes Everything
Outcomes vs Outputs: How Outcome Driven Development Planning Changes EverythingOutcomes vs Outputs: How Outcome Driven Development Planning Changes Everything
Outcomes vs Outputs: How Outcome Driven Development Planning Changes Everything
 
How the WordPress Block Editor Changes the Conversation for Content Editors a...
How the WordPress Block Editor Changes the Conversation for Content Editors a...How the WordPress Block Editor Changes the Conversation for Content Editors a...
How the WordPress Block Editor Changes the Conversation for Content Editors a...
 
How the WordPress Block Editor Changes the Conversation for Content Editors a...
How the WordPress Block Editor Changes the Conversation for Content Editors a...How the WordPress Block Editor Changes the Conversation for Content Editors a...
How the WordPress Block Editor Changes the Conversation for Content Editors a...
 
Who's afraid of the big bad loop?
Who's afraid of the big bad loop?Who's afraid of the big bad loop?
Who's afraid of the big bad loop?
 
Being a better ally
Being a better allyBeing a better ally
Being a better ally
 
Drop Kick Imposter Syndrome
Drop Kick Imposter SyndromeDrop Kick Imposter Syndrome
Drop Kick Imposter Syndrome
 
Awesome Git Workflow for Agencies and Teams
Awesome Git Workflow for Agencies and TeamsAwesome Git Workflow for Agencies and Teams
Awesome Git Workflow for Agencies and Teams
 
9 Things You Didn't Know You Could Do with Your Blog WPSLC
9 Things You Didn't Know You Could Do with Your Blog WPSLC9 Things You Didn't Know You Could Do with Your Blog WPSLC
9 Things You Didn't Know You Could Do with Your Blog WPSLC
 
9 things you didn't know you could do with your blog
9 things you didn't know you could do with your blog9 things you didn't know you could do with your blog
9 things you didn't know you could do with your blog
 

Kürzlich hochgeladen

Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 

Kürzlich hochgeladen (20)

Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 

Why Hacking WordPress Search Isn't Some Big Scary Thing

  • 1. Why Hacking WordPress Search Isn’t Some Big Scary Thing WordCamp SLC 2014 Chris Reynolds @jazzs3quence
  • 3. Who’s this guy? WordPress Developer
  • 4. Who’s this guy? WordPress Developer
  • 5. Who’s this guy? WordPress Developer
  • 6. Who’s this guy? WordPress Developer Course Author
  • 8. 3 misconceptions about search 1.“I don’t know anything about search.”
  • 9. 3 misconceptions about search 1.“I don’t know anything about search.” ?s=some%20query
  • 11. 3 misconceptions about search 2.“WordPress search is hard.”
  • 13. 3 misconceptions about search 3.“WordPress search sucks.”
  • 14. 3 misconceptions about search 3.“WordPress search sucks.” Does what you ask it to.
  • 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)
  • 18. What does WordPress search do? ?s=your%20search
  • 19. What does WordPress search do? ?s=your%20search
  • 20. What does WordPress search do? ?s=your%20search ( $wpdb->posts.post_title LIKE %s ) OR ( $wpdb->posts.post_content LIKE %s )
  • 21. Let me tell you something about query strings and the WordPress Loop
  • 24. What about this? ?cat=music
  • 25. What’s going on? ?cat=music
  • 26. Did you know you can combine these? ?post_type=article&cat=music
  • 27. What’s going on? ?post_type=article& taxonomy=music&term=jazz
  • 28.
  • 32. -?p=123 -?paged=2 -?cat=music -?s=your%20search
  • 33.
  • 34. $args = array( 'post_type' => 'music', 'paged' => $paged, 'orderby' => 'date', 'order' => 'DESC', 'post_status' => 'publish', 'ignore_sticky_posts' => 1 ); ! $my_query = new WP_Query( $args ); ! if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : the_post();
  • 35. $my_query = new WP_Query( 'post_type=music&post_stat us=publish&orderby=date&order=DESC&p aged=' . $paged . '&ignore_sticky_posts=1'); ! if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : the_post();
  • 38. WordPress search isn’t hard You already know all this stuff
  • 39. WordPress search isn’t hard You already know all this stuff You just may not know you know it
  • 40.
  • 41. Ready to have your mind blown?
  • 42. Ready to have your mind blown? You can add all these query args to search
  • 43.
  • 44.
  • 47. How do I actually use this? Like, in a form?
  • 48. <form role="search" method="get" class="search-form" action="' . get_home_url( '/' ) . '"> <label> <input type="search" class="search-field" placeholder="Search" value="" name="s" title="Search for:" /> </label> <input type="hidden" name="music" value="jazz" /> <input type="hidden" name="post_type" value="article" /> </form>
  • 49. <form role="search" method="get" class="search-form" action="' . get_home_url( '/' ) . '"> <label> <input type="search" class="search-field" placeholder="Search" value="" name="s" title="Search for:" /> </label> <input type="hidden" name="music" value="jazz" /> <input type="hidden" name="post_type" value="article" /> </form>
  • 51.
  • 52. posts
  • 55. users songs posts ?s=patrick&post_type%5B%5D=post&post_type%5B %5D=song&post_type%5B%5D=artist
  • 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
  • 60.
  • 61.
  • 62. only search within current taxonomy
  • 63. function nps_get_taxonomy_search_form( $term = null, $taxonomy = null ) { ! if ( !$term ) { $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $term = $term->name; } ! if ( !$taxonomy ) $taxonomy = get_query_var( 'taxonomy' ); ! $form =' <form role="search" method="get" class="search-form" action="' . get_home_url( '/' ) . '"> <label> <input type="search" class="search-field" placeholder="Search" value="" name="s" title="Search for:" /> </label> <input type="hidden" name="' . $taxonomy . '" value="' . $term . '" /> </form> '; ! echo $form; }
  • 64. function nps_get_taxonomy_search_form( $term = null, $taxonomy = null ) { ! if ( !$term ) { $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $term = $term->name; } ! if ( !$taxonomy ) $taxonomy = get_query_var( 'taxonomy' ); ! $form =' <form role="search" method="get" class="search-form" action="' . get_home_url( '/' ) . '"> <label> <input type="search" class="search-field" placeholder="Search" value="" name="s" title="Search for:" /> </label> <input type="hidden" name="' . $taxonomy . '" value="' . $term . '" /> </form> '; ! echo $form; } http://s3q.us/wcslc2014- nps-searchform
  • 65. Where does that leave us?
  • 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.
  • 70. Questions? Chris Reynolds @jazzs3quence
  • 71. Questions? Chris Reynolds @jazzs3quence Pluralsight Courses — http://s3q.us/cr-ps
  • 72. Questions? Chris Reynolds @jazzs3quence Pluralsight Courses — http://s3q.us/cr-ps These slides — http://s3q.us/wcslc2014
  • 73. Questions? Chris Reynolds @jazzs3quence Pluralsight Courses — http://s3q.us/cr-ps These slides — http://s3q.us/wcslc2014 Search form gist — http://s3q.us/wcslc2014-nps-searchform
  • 74. Questions? Chris Reynolds @jazzs3quence Pluralsight Courses — http://s3q.us/cr-ps These slides — http://s3q.us/wcslc2014 Search form gist — http://s3q.us/wcslc2014-nps-searchform Search page gist — http://s3q.us/wcslc2014-cs-search