SlideShare a Scribd company logo
Parsing Strange:URL to SQL to HTML Hal Stern http://snowmanonfire.com headshot by Richard Stevenshttp://dieselsweeties.com
Why Do You Care? Database performance = user experience A little database expertise goes a long way Use taxonomies for more than sidebar lists WordPress is a powerful CMS Change default behaviors Defy the common wisdom Integrate other content sources/filters WordCamp Chicago 2
Disclaimers I’m somewhat social, for Jersey I’m (old) old school If using PHP echo gives you hives……take a Benadryl now If “INNER JOIN” makes you giggle, you’re in the wrong session/conference/fantasy I suck at art and design 3 WordCamp Chicago
Flow of Control Web server URL manipulation Real file or permalink URL? URL to query variables What to display? Tag? Post? Category? Query variables to SQL generation How exactly to get that content? Template file selection How will content be displayed? Content manipulation 4 WordCamp Chicago
Whose File Is This? User URL request passed to web server Web server checks.htaccessfile WP install root  Other .htaccessfiles may interfere Basic rewriting rules:If file or directory URL doesn’t exist, start WordPress via index.php WordCamp Chicago 5 <IfModulemod_rewrite.c> RewriteEngine On RewriteBase /whereyouputWordPress/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
What Happens Before The Loop Parse URL into a query Set conditionals & select templates Execute the query & cache results Run the Loop:<?phpif (have_posts()) : 	   while (have_posts()) : the_post();    //loop contentendwhile;endif;?> WordCamp Chicago 6
Examining the Query String SQL passed to MySQL in WP_Query object’s request element Brute force: edit theme footer.phpto see main loop’s query for displayed page WordCamp Chicago 7 <?php   global $wp_query;   echo ”SQL for this page ";   echo $wp_query->request;   echo "<br>"; ?>
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post’ AND(wp_posts.post_status = 'publish' ORwp_posts.post_status = 'private’)ORDER BY wp_posts.post_date DESC LIMIT 0, 10 “Home Page” Query Deconstruction WordCamp Chicago 8 Get all fields from posts table, but limit number of returned rows Only get posts, and those that are published or private to the user Sort the results by date in descending order Start results starting with record 0 and up to 10 more results
Query Parsing parse_request() method of WP_Query extracts query variables from URL Execute rewrite rules Pick off ?p=67 style http GET variables Match permalink structure Match keywords like “author” and “tag” WordCamp Chicago 9
Query Variables to SQL Query type: post by title, posts by category or tag, posts by date Variables for the query Slug values for category/tags Month/day numbers Explicit variable values?p=67 for post_id WordCamp Chicago 10
Simple Title Slug Parsing Rewrite matches root of permalink, extracts tail of URL as a title slug WordCamp Chicago 11 /2010/premio-sausage SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND YEAR(wp_posts.post_date)='2010' AND wp_posts.post_name = 'premio-sausage' AND wp_posts.post_type = 'post' ORDER BY wp_posts.post_date DESC
Graphs and JOIN Operations WordPress treats tags and categories as “terms”, mapped 1:N to posts Relational databases aren’t ideal for this INNER JOIN builds intermediate tables on common key values Following link in a social graph is equivalent to an INNER JOIN on tables of linked items WordCamp Chicago 12
WordPress Taxonomy Tables Term relationships table maps N:1 terms to each post Term taxonomy maps slugs 1:N to taxonomies Term table has slugs for URL mapping WordCamp Chicago 13 wp_term_relationshipsobject_idterm_taxonomy_id wp_postspost_id….post_date…  post_content wp_term_taxonomyterm_taxonomy_idterm_idtaxonomydescription wp_terms term_idnameslug
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_postsINNER JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id)INNER JOIN wp_term_taxonomy ON  (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)INNER JOIN wp_terms ON   (wp_term_taxonomy.term_id = wp_terms.term_id)WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'post_tag' AND wp_terms.slug IN ('premio') AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10 Taxonomy Lookup WordCamp Chicago 14 /tag/premio
More on Canonical URLs Canonical URLs improve SEO WordPress is really good about generating 301 Redirects for non-standard URLs Example: URL doesn’t appear to match a permalink, WordPress does prediction Use “LIKE title%” in WHERE clause Matches “title” as initial substring with % wildcard WordCamp Chicago 15
Modifying the Query Brute force isn’t necessarily good Using query_posts() ignores all previous parsing, runs a new SQL query Filter query_vars Change default parsing (convert any day to a week’s worth of posts, for example) Actions parse_query & parse_request Access WP_Query object before execution is_xx() conditionals are already set WordCamp Chicago 16
SQL Generation Filters posts_where More explicit control over query variable to SQL grammar mapping posts_join Add or modify JOINS for other graph like relationships Many other filters Change grouping of results Change ordering of results WordCamp Chicago 17
Applications Stylized listings Category sorted alphabetically Use posts as listings of resources (jobs, clients, events) Custom URL slugs Add rewrite rules to match slug and set query variables Joining other social graphs Suggested/related content WordCamp Chicago 18
Template File Selection is_x() conditionals set in query parsing Used to drive template selection is_tag() looks for tag-slug, tag-id, then tag Full search hierarchy in Codex template_redirectaction Called in the template loader Add actions to override defaults WordCamp Chicago 19
HTML Generation Done in the_post() method Raw content retrieved from MySQL Short codes interpreted CSS applied Some caching plugins generate and store HTML, so YMMV WordCamp Chicago 20
Why Do You Care? User experience improvement JOINS are expensive Large table, repetitive SELECTs = slow Running query once keeps cache warm Category, permalink, title slug choices matter More CMS, less “blog” Alphabetical sort Adding taxonomy/social graph elements WordCamp Chicago 21
Blunt Self-Promotion Brad and David are here, too They’re significantly more WP literate than me This slide was more helpful yesterday 22 WordCamp Chicago
Resources Core files where SQL stuff happens query.php post.php canonical.php Template loader search path http://codex.wordpress.org/Template_Hierarchy WordCamp Chicago 23
Contact Hal Stern freeholdhal@gmail.com @freeholdhal http://snowmanonfire.com http://facebook.com/hal.stern http://slideshare.net/freeholdhal WordCamp Chicago 24

More Related Content

What's hot

Google Search Tips
Google Search TipsGoogle Search Tips
Google Search Tips
Mark Rotondella
 
Architecture of a search engine
Architecture of a search engineArchitecture of a search engine
Architecture of a search engine
Sylvain Utard
 
Internet with HTML
Internet with HTMLInternet with HTML
Internet with HTML
umesh patil
 
SharePoint Intelligence Introduction To Share Point Designer Workflows
SharePoint Intelligence Introduction To Share Point Designer WorkflowsSharePoint Intelligence Introduction To Share Point Designer Workflows
SharePoint Intelligence Introduction To Share Point Designer Workflows
Ivan Sanders
 
Google Search Techniques
Google Search TechniquesGoogle Search Techniques
Google Search Techniques
Duc Chau
 
Html5 final
Html5 finalHtml5 final
Html5 final
saransh_kataria
 
How to create rss feed for your website
How to create  rss feed  for  your  websiteHow to create  rss feed  for  your  website
How to create rss feed for your website
OM Maurya
 
How to create rss feed
How to create rss feedHow to create rss feed
How to create rss feed
Tanuja Talekar
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
Vladimir Valencia
 
Google Scholar
Google ScholarGoogle Scholar
Google Scholar
Amanda Starkel
 
How to build a custom search engine
How to build a custom search engineHow to build a custom search engine
How to build a custom search engine
searchbox-com
 
Mpl brownbag sept2011
Mpl brownbag sept2011Mpl brownbag sept2011
Mpl brownbag sept2011
Jason Coleman
 
Google power search
Google power searchGoogle power search
Google power search
Muhammed Shokr
 
Google searching techniques
Google searching techniquesGoogle searching techniques
Google searching techniques
abbas mohd
 
Making The Most Out Of Google
Making The Most Out Of GoogleMaking The Most Out Of Google
Making The Most Out Of Google
Kieran Lamb
 
Customised Search With Google
Customised Search With GoogleCustomised Search With Google
Customised Search With Google
Dave Briggs
 

What's hot (18)

Google Search Tips
Google Search TipsGoogle Search Tips
Google Search Tips
 
Architecture of a search engine
Architecture of a search engineArchitecture of a search engine
Architecture of a search engine
 
Internet with HTML
Internet with HTMLInternet with HTML
Internet with HTML
 
SharePoint Intelligence Introduction To Share Point Designer Workflows
SharePoint Intelligence Introduction To Share Point Designer WorkflowsSharePoint Intelligence Introduction To Share Point Designer Workflows
SharePoint Intelligence Introduction To Share Point Designer Workflows
 
Google Search Techniques
Google Search TechniquesGoogle Search Techniques
Google Search Techniques
 
Html5 final
Html5 finalHtml5 final
Html5 final
 
How to create rss feed for your website
How to create  rss feed  for  your  websiteHow to create  rss feed  for  your  website
How to create rss feed for your website
 
How to create rss feed
How to create rss feedHow to create rss feed
How to create rss feed
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
 
Google Scholar
Google ScholarGoogle Scholar
Google Scholar
 
How to build a custom search engine
How to build a custom search engineHow to build a custom search engine
How to build a custom search engine
 
Google search tips
Google search tipsGoogle search tips
Google search tips
 
Mpl brownbag sept2011
Mpl brownbag sept2011Mpl brownbag sept2011
Mpl brownbag sept2011
 
Google power search
Google power searchGoogle power search
Google power search
 
Google searching techniques
Google searching techniquesGoogle searching techniques
Google searching techniques
 
xml sitemap
xml sitemapxml sitemap
xml sitemap
 
Making The Most Out Of Google
Making The Most Out Of GoogleMaking The Most Out Of Google
Making The Most Out Of Google
 
Customised Search With Google
Customised Search With GoogleCustomised Search With Google
Customised Search With Google
 

Viewers also liked

Parsing strange v2
Parsing strange v2Parsing strange v2
Parsing strange v2Hal Stern
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4Hal Stern
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4Hal Stern
 
Parsing strange v3
Parsing strange v3Parsing strange v3
Parsing strange v3Hal Stern
 
Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1Veselina Nikolova
 
Shades team in action
Shades team in actionShades team in action
Shades team in action
Donna Roberts
 
Stephen Rathinaraj Corr
Stephen Rathinaraj   CorrStephen Rathinaraj   Corr
Stephen Rathinaraj Corrfarsiya
 
Stephen 205 (1)
Stephen 205 (1)Stephen 205 (1)
Stephen 205 (1)farsiya
 
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...Veselina Nikolova
 
Teoria de control presentacion
Teoria de control presentacionTeoria de control presentacion
Teoria de control presentacion
cesar
 
100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docx100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docx
cesar
 

Viewers also liked (17)

Faces all
Faces allFaces all
Faces all
 
ЕГДБ
ЕГДБЕГДБ
ЕГДБ
 
Parsing strange v2
Parsing strange v2Parsing strange v2
Parsing strange v2
 
Ogra s3-2010 success
Ogra s3-2010 successOgra s3-2010 success
Ogra s3-2010 success
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
 
11 13
11 1311 13
11 13
 
Presentation sofia
Presentation sofiaPresentation sofia
Presentation sofia
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
 
Parsing strange v3
Parsing strange v3Parsing strange v3
Parsing strange v3
 
Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1
 
Ogra s4-2010 tenders
Ogra s4-2010 tendersOgra s4-2010 tenders
Ogra s4-2010 tenders
 
Shades team in action
Shades team in actionShades team in action
Shades team in action
 
Stephen Rathinaraj Corr
Stephen Rathinaraj   CorrStephen Rathinaraj   Corr
Stephen Rathinaraj Corr
 
Stephen 205 (1)
Stephen 205 (1)Stephen 205 (1)
Stephen 205 (1)
 
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
 
Teoria de control presentacion
Teoria de control presentacionTeoria de control presentacion
Teoria de control presentacion
 
100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docx100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docx
 

Similar to Parsing strange v1.1

Parsing strange v3
Parsing strange v3Parsing strange v3
Parsing strange v3Hal Stern
 
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...
MATCHmaster
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012Stephanie Leary
 
Building social and RESTful frameworks
Building social and RESTful frameworksBuilding social and RESTful frameworks
Building social and RESTful frameworksbrendonschwartz
 
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
Tobias Koprowski
 
PV Standard Search Query
PV Standard Search QueryPV Standard Search Query
PV Standard Search Query
ProdigyView
 
Customizing SharePoint 2013 search display templates
Customizing SharePoint 2013 search display templatesCustomizing SharePoint 2013 search display templates
Customizing SharePoint 2013 search display templates
Tony Testa
 
Cegonsoft-Php training institute Bangalore
Cegonsoft-Php training institute BangaloreCegonsoft-Php training institute Bangalore
Cegonsoft-Php training institute Bangaloredhivyas19
 
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO MeetupTroubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
patrickstox
 
Advanced Drupal SEO - Beginner to Expert in 60 Minutes
Advanced Drupal SEO - Beginner to Expert in 60 MinutesAdvanced Drupal SEO - Beginner to Expert in 60 Minutes
Advanced Drupal SEO - Beginner to Expert in 60 Minutes
Tom McCracken
 
Spsvb Developer Intro to SharePoint Search
Spsvb   Developer Intro to SharePoint SearchSpsvb   Developer Intro to SharePoint Search
Spsvb Developer Intro to SharePoint Search
Michael Oryszak
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome Measures
Steven Johnson
 
Alternative discovery and_seo_fee-stephan_spencer
Alternative discovery and_seo_fee-stephan_spencerAlternative discovery and_seo_fee-stephan_spencer
Alternative discovery and_seo_fee-stephan_spencerzachbrowne
 
Child Themes in WordPress
Child Themes in WordPressChild Themes in WordPress
Child Themes in WordPress
Jeff Cohan
 
Spca2014 search workshop niaulin
Spca2014 search workshop niaulinSpca2014 search workshop niaulin
Spca2014 search workshop niaulinNCCOMMS
 
SEO Mistake From Blogger
SEO Mistake From BloggerSEO Mistake From Blogger
SEO Mistake From Blogger
Seo Indonesia
 
SEO Method For Blogger
SEO Method For BloggerSEO Method For Blogger
SEO Method For Blogger
Seo Indonesia
 
Cegonsoft PHP training institute in Bnaglaore
Cegonsoft PHP training institute in BnaglaoreCegonsoft PHP training institute in Bnaglaore
Cegonsoft PHP training institute in BnaglaoreCegonsoft Fames
 

Similar to Parsing strange v1.1 (20)

Parsing strange v3
Parsing strange v3Parsing strange v3
Parsing strange v3
 
Article16
Article16Article16
Article16
 
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
 
Building social and RESTful frameworks
Building social and RESTful frameworksBuilding social and RESTful frameworks
Building social and RESTful frameworks
 
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
 
PV Standard Search Query
PV Standard Search QueryPV Standard Search Query
PV Standard Search Query
 
Customizing SharePoint 2013 search display templates
Customizing SharePoint 2013 search display templatesCustomizing SharePoint 2013 search display templates
Customizing SharePoint 2013 search display templates
 
Cegonsoft-Php training institute Bangalore
Cegonsoft-Php training institute BangaloreCegonsoft-Php training institute Bangalore
Cegonsoft-Php training institute Bangalore
 
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO MeetupTroubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
 
Advanced Drupal SEO - Beginner to Expert in 60 Minutes
Advanced Drupal SEO - Beginner to Expert in 60 MinutesAdvanced Drupal SEO - Beginner to Expert in 60 Minutes
Advanced Drupal SEO - Beginner to Expert in 60 Minutes
 
Spsvb Developer Intro to SharePoint Search
Spsvb   Developer Intro to SharePoint SearchSpsvb   Developer Intro to SharePoint Search
Spsvb Developer Intro to SharePoint Search
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome Measures
 
Alternative discovery and_seo_fee-stephan_spencer
Alternative discovery and_seo_fee-stephan_spencerAlternative discovery and_seo_fee-stephan_spencer
Alternative discovery and_seo_fee-stephan_spencer
 
Child Themes in WordPress
Child Themes in WordPressChild Themes in WordPress
Child Themes in WordPress
 
Spca2014 search workshop niaulin
Spca2014 search workshop niaulinSpca2014 search workshop niaulin
Spca2014 search workshop niaulin
 
SEO Mistake From Blogger
SEO Mistake From BloggerSEO Mistake From Blogger
SEO Mistake From Blogger
 
SEO Mistakes
SEO MistakesSEO Mistakes
SEO Mistakes
 
SEO Method For Blogger
SEO Method For BloggerSEO Method For Blogger
SEO Method For Blogger
 
Cegonsoft PHP training institute in Bnaglaore
Cegonsoft PHP training institute in BnaglaoreCegonsoft PHP training institute in Bnaglaore
Cegonsoft PHP training institute in Bnaglaore
 

Recently uploaded

From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

Parsing strange v1.1

  • 1. Parsing Strange:URL to SQL to HTML Hal Stern http://snowmanonfire.com headshot by Richard Stevenshttp://dieselsweeties.com
  • 2. Why Do You Care? Database performance = user experience A little database expertise goes a long way Use taxonomies for more than sidebar lists WordPress is a powerful CMS Change default behaviors Defy the common wisdom Integrate other content sources/filters WordCamp Chicago 2
  • 3. Disclaimers I’m somewhat social, for Jersey I’m (old) old school If using PHP echo gives you hives……take a Benadryl now If “INNER JOIN” makes you giggle, you’re in the wrong session/conference/fantasy I suck at art and design 3 WordCamp Chicago
  • 4. Flow of Control Web server URL manipulation Real file or permalink URL? URL to query variables What to display? Tag? Post? Category? Query variables to SQL generation How exactly to get that content? Template file selection How will content be displayed? Content manipulation 4 WordCamp Chicago
  • 5. Whose File Is This? User URL request passed to web server Web server checks.htaccessfile WP install root Other .htaccessfiles may interfere Basic rewriting rules:If file or directory URL doesn’t exist, start WordPress via index.php WordCamp Chicago 5 <IfModulemod_rewrite.c> RewriteEngine On RewriteBase /whereyouputWordPress/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
  • 6. What Happens Before The Loop Parse URL into a query Set conditionals & select templates Execute the query & cache results Run the Loop:<?phpif (have_posts()) : while (have_posts()) : the_post(); //loop contentendwhile;endif;?> WordCamp Chicago 6
  • 7. Examining the Query String SQL passed to MySQL in WP_Query object’s request element Brute force: edit theme footer.phpto see main loop’s query for displayed page WordCamp Chicago 7 <?php global $wp_query; echo ”SQL for this page "; echo $wp_query->request; echo "<br>"; ?>
  • 8. SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post’ AND(wp_posts.post_status = 'publish' ORwp_posts.post_status = 'private’)ORDER BY wp_posts.post_date DESC LIMIT 0, 10 “Home Page” Query Deconstruction WordCamp Chicago 8 Get all fields from posts table, but limit number of returned rows Only get posts, and those that are published or private to the user Sort the results by date in descending order Start results starting with record 0 and up to 10 more results
  • 9. Query Parsing parse_request() method of WP_Query extracts query variables from URL Execute rewrite rules Pick off ?p=67 style http GET variables Match permalink structure Match keywords like “author” and “tag” WordCamp Chicago 9
  • 10. Query Variables to SQL Query type: post by title, posts by category or tag, posts by date Variables for the query Slug values for category/tags Month/day numbers Explicit variable values?p=67 for post_id WordCamp Chicago 10
  • 11. Simple Title Slug Parsing Rewrite matches root of permalink, extracts tail of URL as a title slug WordCamp Chicago 11 /2010/premio-sausage SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND YEAR(wp_posts.post_date)='2010' AND wp_posts.post_name = 'premio-sausage' AND wp_posts.post_type = 'post' ORDER BY wp_posts.post_date DESC
  • 12. Graphs and JOIN Operations WordPress treats tags and categories as “terms”, mapped 1:N to posts Relational databases aren’t ideal for this INNER JOIN builds intermediate tables on common key values Following link in a social graph is equivalent to an INNER JOIN on tables of linked items WordCamp Chicago 12
  • 13. WordPress Taxonomy Tables Term relationships table maps N:1 terms to each post Term taxonomy maps slugs 1:N to taxonomies Term table has slugs for URL mapping WordCamp Chicago 13 wp_term_relationshipsobject_idterm_taxonomy_id wp_postspost_id….post_date… post_content wp_term_taxonomyterm_taxonomy_idterm_idtaxonomydescription wp_terms term_idnameslug
  • 14. SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_postsINNER JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id)INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)INNER JOIN wp_terms ON (wp_term_taxonomy.term_id = wp_terms.term_id)WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'post_tag' AND wp_terms.slug IN ('premio') AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10 Taxonomy Lookup WordCamp Chicago 14 /tag/premio
  • 15. More on Canonical URLs Canonical URLs improve SEO WordPress is really good about generating 301 Redirects for non-standard URLs Example: URL doesn’t appear to match a permalink, WordPress does prediction Use “LIKE title%” in WHERE clause Matches “title” as initial substring with % wildcard WordCamp Chicago 15
  • 16. Modifying the Query Brute force isn’t necessarily good Using query_posts() ignores all previous parsing, runs a new SQL query Filter query_vars Change default parsing (convert any day to a week’s worth of posts, for example) Actions parse_query & parse_request Access WP_Query object before execution is_xx() conditionals are already set WordCamp Chicago 16
  • 17. SQL Generation Filters posts_where More explicit control over query variable to SQL grammar mapping posts_join Add or modify JOINS for other graph like relationships Many other filters Change grouping of results Change ordering of results WordCamp Chicago 17
  • 18. Applications Stylized listings Category sorted alphabetically Use posts as listings of resources (jobs, clients, events) Custom URL slugs Add rewrite rules to match slug and set query variables Joining other social graphs Suggested/related content WordCamp Chicago 18
  • 19. Template File Selection is_x() conditionals set in query parsing Used to drive template selection is_tag() looks for tag-slug, tag-id, then tag Full search hierarchy in Codex template_redirectaction Called in the template loader Add actions to override defaults WordCamp Chicago 19
  • 20. HTML Generation Done in the_post() method Raw content retrieved from MySQL Short codes interpreted CSS applied Some caching plugins generate and store HTML, so YMMV WordCamp Chicago 20
  • 21. Why Do You Care? User experience improvement JOINS are expensive Large table, repetitive SELECTs = slow Running query once keeps cache warm Category, permalink, title slug choices matter More CMS, less “blog” Alphabetical sort Adding taxonomy/social graph elements WordCamp Chicago 21
  • 22. Blunt Self-Promotion Brad and David are here, too They’re significantly more WP literate than me This slide was more helpful yesterday 22 WordCamp Chicago
  • 23. Resources Core files where SQL stuff happens query.php post.php canonical.php Template loader search path http://codex.wordpress.org/Template_Hierarchy WordCamp Chicago 23
  • 24. Contact Hal Stern freeholdhal@gmail.com @freeholdhal http://snowmanonfire.com http://facebook.com/hal.stern http://slideshare.net/freeholdhal WordCamp Chicago 24

Editor's Notes

  1. SQL_CALC_FOUND_ROWS limits the number of returned rows via the LIMIT clause, and ensures that you don’t tax MySQL,Perform immense queries (SMOF has 600 post entries)WHERE 1=1 is for building compound where clauses; ensures there’s no degenerate caseType=post versus revision; status publish/private versus draft, trash
  2. Look at rewrite.php, and canonical.php (more on that later)Default terms of “tag” and “category” can be changed in the Settings/Permalinks section of the Dashboard
  3. Separate namespaces for pages and postsWhat about parent pages?In this example the permalink structure is %year%/%title%
  4. Three joins needed to build the full cartesian product of related tables.Get all of the terms that have a slug of “premio”, and find out what taxonomies they’re inGet the taxonomies that are post tags, and find all taxonomy object ids (that are post tags of slug “premio”)Get all of the posts that have this object id associated with them from term_relationshipsOrder the final table by post date,starting with the most recent (0) and getting 10 of them.
  5. Don’t want multiple URLs pointing to the same page, so canonical parsing cleans them up