SlideShare una empresa de Scribd logo
1 de 28
© 2010 Hal Stern
Some Rights Reserved
Parsing Strange:
URL to SQL to HTML
Hal Stern
snowmanonfire.com
slideshare.net/freeholdhal
headshot by Richard Stevens
http://dieselsweeties.com
© 2010 Hal Stern
Some Rights Reserved
Why Do You Care?
• Database performance = user experience
• A little database expertise goes a long way
• Taxonomies for more than sidebar lists
• Custom post types
• WordPress as a powerful CMS >> blog
> Change default behaviors
> Defy the common wisdom
> Integrate other content sources/filters
WordCamp Philly 2010 2
© 2010 Hal Stern
Some Rights Reserved
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
3WordCamp Philly 2010
© 2010 Hal Stern
Some Rights Reserved
Whose File Is This?
• User URL request passed to web server
• Web server checks
.htaccess file
> WP install root
> Other .htaccess
files may interfere
• Basic rewriting rules:
If file or directory URL doesn’t exist, start
WordPress via index.php
WordCamp Philly 2010 4
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /whereyouputWordPress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
© 2010 Hal Stern
Some Rights Reserved
Example Meta Fail: 404 Not Found
• Access broken image URLs for
unintended results: no 404 pages!
myblog/images/not-a-pic.jpg
• Web server can’t find file, assumes it’s a
permalink, hands to WP
• WP can’t interpret it, so defaults to home
WordCamp Philly 2010 5
myblog/
myblog/wp-content (etc)
myblog/images
© 2010 Hal Stern
Some Rights Reserved
What Happens Before The Loop
• Parse URL into a query
• Set conditionals & select templates
• Execute the query & cache results
• Run the Loop:
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
//loop content
endwhile;
endif;
?>
WordCamp Philly 2010 6
© 2010 Hal Stern
Some Rights Reserved
Examining the Query String
• SQL passed to MySQL in WP_Query
object’s request element
• Brute force: edit theme footer.php to
see main loop’s query for displayed page
WordCamp Philly 2010 7
<?php
global $wp_query;
echo ”SQL for this page ";
echo $wp_query->request;
echo "<br>";
?>
© 2010 Hal Stern
Some Rights Reserved
“Home Page” Query Deconstruction
WordCamp Philly 2010 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' OR
wp_posts.post_status = 'private’)
ORDER BY wp_posts.post_date DESC LIMIT 0, 10
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
© 2010 Hal Stern
Some Rights Reserved
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”
> Match custom post type slugs
WordCamp Philly 2010 9
© 2010 Hal Stern
Some Rights Reserved
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
• post_type variable has been around for
a while; CPT queries fill in new values
WordCamp Philly 2010 10
© 2010 Hal Stern
Some Rights Reserved
Simple Title Slug Parsing
• Rewrite matches root of permalink,
extracts tail of URL as a title slug
WordCamp Philly 2010 11
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
/2010/premio-sausage
© 2010 Hal Stern
Some Rights Reserved
CPT Query Variables
• Register CPT with a custom query variable
'query_var' => 'ebay'
• Variable works in URLs like built-ins
myblog.com/?ebay=current_items
myblog.com/?ebay=cool_searches
• Variable value matches CPT title slug
WordCamp Philly 2010 12
© 2010 Hal Stern
Some Rights Reserved
WordPress Meta Data
• Common DB mechanics for all meta data
> Categories, tags, custom taxonomies
• Normalized down to 3 tables
> Terms: word strings and their slugs
> Taxonomies: collections of terms
> Relationships: terms attached to posts
• It’s so simple it gets really complex.
Really.
WordCamp Philly 2010 13
© 2010 Hal Stern
Some Rights Reserved
Graphs and JOIN Operations
• WordPress maps tags and categories 1:N
to posts (each term in many posts)
• You need to punch MySQL to handle
hierarchical, multi-valued relations
> INNER JOIN builds intermediate tables on
common key values
• Following link in a graph is equivalent to
an INNER JOIN on tables of linked items
WordCamp Philly 2010 14
© 2010 Hal Stern
Some Rights Reserved
WordPress Taxonomy Tables
• Term relationships table maps
N terms to each post
• Term taxonomy maps N
terms to each taxonomy
• Term table has slugs for URL
mapping
WordCamp Philly 2010 15
wp_term_relationships
object_id
term_taxonomy_id
wp_posts
post_id
….
post_date
…
post_content
wp_term_taxonomy
term_taxonomy_id
term_id
taxonomy
description
wp_terms
term_id
name
slug
© 2010 Hal Stern
Some Rights Reserved
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts
INNER 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 Philly 2010 16
/tag/premio
© 2010 Hal Stern
Some Rights Reserved
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 Philly 2010 17
© 2010 Hal Stern
Some Rights Reserved
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 Philly 2010 18
© 2010 Hal Stern
Some Rights Reserved
SQL Generation Filters
• posts_where
> More explicit control over query variable to
SQL grammar mapping
• posts_join
> Add or modify JOIN operations for other
graph relationships
• Many other filters
> Change grouping of results
> Change ordering of results
WordCamp Philly 2010 19
© 2010 Hal Stern
Some Rights Reserved
Custom Post Types
• Change SQL WHERE clause on post type
> wp_posts.post_type=‘ebay’
• Add new rewrite rules for URL parsing similar
to category & tag
> Set slug in CPT registration array
'rewrite' => array ("slug" => “ebay”)
• Watch out for competing, overwritten or
unflushed rewrite entries
<?php echo "<pre>”;
print_r(get_option('rewrite_rules'));
echo "</pre>”;
?>
WordCamp Philly 2010 20
© 2010 Hal Stern
Some Rights Reserved
Applications
• Stylized listings
> Category sorted alphabetically
> Use posts as listings of resources (jobs,
clients, events) – use CPT for more control
• Custom URL slugs
> Add rewrite rules to match slug and set query
variables
• Joining other social graphs
> Suggested/related content
WordCamp Philly 2010 21
© 2010 Hal Stern
Some Rights Reserved
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_redirect action
> Called in the template loader
> Add actions to override defaults
WordCamp Philly 2010 22
© 2010 Hal Stern
Some Rights Reserved
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 Philly 2010 23
© 2010 Hal Stern
Some Rights Reserved
More Complex Example
• For category or tag templates, intersperse
custom post types into the results, sorting
by post date or alphabetically by title.
• Attach filter to posts_where:
if (query is for a category or tag)
$where = ‘(‘ . $where . ‘)’ .
“OR post_type=‘extras’” ;
• This changes the database query…..
WordCamp Philly 2010 24
© 2010 Hal Stern
Some Rights Reserved
Matching Tags
• What if you want to match tags from user-
selected posts to tagged CPT posts?
• Need to get the list of tags from the main
loop query
• In template, create a new query looking for
post_type=‘cpt type’
• Use JOIN to match collected tags to tags
in the CPT (or other custom) taxonomy
WordCamp Philly 2010 25
© 2010 Hal Stern
Some Rights Reserved
Why Do You Care?
• User experience improvement
> JOINS are expensive
> Large post 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 Philly 2010 26
© 2010 Hal Stern
Some Rights Reserved
Resources
• Core files where SQL stuff happens
> query.php
> post.php
> canonical.php
> rewrite.php
• Template loader search path
> http://codex.wordpress.org/Template_Hierarchy
WordCamp Philly 2010 27
© 2010 Hal Stern
Some Rights Reserved
Contact (Shameless Plug)
Hal Stern
freeholdhal@gmail.com
@freeholdhal
snowmanonfire.com
facebook.com/hal.stern
slideshare.net/freeholdhal
WordCamp Philly 2010 28

Más contenido relacionado

La actualidad más candente

Building Intelligent Search Applications with Apache Solr and PHP5
Building Intelligent Search Applications with Apache Solr and PHP5Building Intelligent Search Applications with Apache Solr and PHP5
Building Intelligent Search Applications with Apache Solr and PHP5israelekpo
 
Using Apache Solr
Using Apache SolrUsing Apache Solr
Using Apache Solrpittaya
 
Introduction to Apache Solr.
Introduction to Apache Solr.Introduction to Apache Solr.
Introduction to Apache Solr.ashish0x90
 
Parsing strange v1.1
Parsing strange v1.1Parsing strange v1.1
Parsing strange v1.1Hal Stern
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection apiMatthieu Aubry
 
Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)Sander Mak (@Sander_Mak)
 
.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11aminmesbahi
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local StorageLior Zamir
 
Building your own search engine with Apache Solr
Building your own search engine with Apache SolrBuilding your own search engine with Apache Solr
Building your own search engine with Apache SolrBiogeeks
 
Solving real world data problems with Jerakia
Solving real world data problems with JerakiaSolving real world data problems with Jerakia
Solving real world data problems with JerakiaCraig Dunn
 
.NET Core, ASP.NET Core Course, Session 7
.NET Core, ASP.NET Core Course, Session 7.NET Core, ASP.NET Core Course, Session 7
.NET Core, ASP.NET Core Course, Session 7aminmesbahi
 
New-Age Search through Apache Solr
New-Age Search through Apache SolrNew-Age Search through Apache Solr
New-Age Search through Apache SolrEdureka!
 
SEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePointSEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePointMarc D Anderson
 
Battle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchBattle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchRafał Kuć
 
OSB 12c - Database Polling using DB adapter - Oracle Fusion Middleware Blog
OSB 12c - Database Polling using DB adapter - Oracle Fusion Middleware BlogOSB 12c - Database Polling using DB adapter - Oracle Fusion Middleware Blog
OSB 12c - Database Polling using DB adapter - Oracle Fusion Middleware BlogTUSHAR VARSHNEY
 

La actualidad más candente (20)

Building Intelligent Search Applications with Apache Solr and PHP5
Building Intelligent Search Applications with Apache Solr and PHP5Building Intelligent Search Applications with Apache Solr and PHP5
Building Intelligent Search Applications with Apache Solr and PHP5
 
Apache Solr
Apache SolrApache Solr
Apache Solr
 
Using Apache Solr
Using Apache SolrUsing Apache Solr
Using Apache Solr
 
Apache Solr Workshop
Apache Solr WorkshopApache Solr Workshop
Apache Solr Workshop
 
Introduction to Apache Solr.
Introduction to Apache Solr.Introduction to Apache Solr.
Introduction to Apache Solr.
 
Parsing strange v1.1
Parsing strange v1.1Parsing strange v1.1
Parsing strange v1.1
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
 
Local storage
Local storageLocal storage
Local storage
 
Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)
 
.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11
 
Solr Presentation
Solr PresentationSolr Presentation
Solr Presentation
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local Storage
 
Building your own search engine with Apache Solr
Building your own search engine with Apache SolrBuilding your own search engine with Apache Solr
Building your own search engine with Apache Solr
 
Solving real world data problems with Jerakia
Solving real world data problems with JerakiaSolving real world data problems with Jerakia
Solving real world data problems with Jerakia
 
.NET Core, ASP.NET Core Course, Session 7
.NET Core, ASP.NET Core Course, Session 7.NET Core, ASP.NET Core Course, Session 7
.NET Core, ASP.NET Core Course, Session 7
 
Quiery builder
Quiery builderQuiery builder
Quiery builder
 
New-Age Search through Apache Solr
New-Age Search through Apache SolrNew-Age Search through Apache Solr
New-Age Search through Apache Solr
 
SEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePointSEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePoint
 
Battle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchBattle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearch
 
OSB 12c - Database Polling using DB adapter - Oracle Fusion Middleware Blog
OSB 12c - Database Polling using DB adapter - Oracle Fusion Middleware BlogOSB 12c - Database Polling using DB adapter - Oracle Fusion Middleware Blog
OSB 12c - Database Polling using DB adapter - Oracle Fusion Middleware Blog
 

Destacado

Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1Veselina Nikolova
 
Stephen 205 (1)
Stephen 205 (1)Stephen 205 (1)
Stephen 205 (1)farsiya
 
Stephen Rathinaraj Corr
Stephen Rathinaraj   CorrStephen Rathinaraj   Corr
Stephen Rathinaraj Corrfarsiya
 
Shades team in action
Shades team in actionShades team in action
Shades team in actionDonna Roberts
 
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 presentacioncesar
 
100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docx100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docxcesar
 

Destacado (13)

Ogra s3-2010 success
Ogra s3-2010 successOgra s3-2010 success
Ogra s3-2010 success
 
Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1
 
ЕГДБ
ЕГДБЕГДБ
ЕГДБ
 
Faces all
Faces allFaces all
Faces all
 
Presentation sofia
Presentation sofiaPresentation sofia
Presentation sofia
 
11 13
11 1311 13
11 13
 
Ogra s4-2010 tenders
Ogra s4-2010 tendersOgra s4-2010 tenders
Ogra s4-2010 tenders
 
Stephen 205 (1)
Stephen 205 (1)Stephen 205 (1)
Stephen 205 (1)
 
Stephen Rathinaraj Corr
Stephen Rathinaraj   CorrStephen Rathinaraj   Corr
Stephen Rathinaraj Corr
 
Shades team in action
Shades team in actionShades team in action
Shades team in action
 
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 a Parsing strange v4

The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012Stephanie Leary
 
PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptxnatesanp1234
 
Wordpress theme development
Wordpress theme developmentWordpress theme development
Wordpress theme developmentNaeem Junejo
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPressTaylor Lovett
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Lucidworks
 
Power Automate Techniques that "Save
Power Automate Techniques that "SavePower Automate Techniques that "Save
Power Automate Techniques that "SaveThomas Duff
 
Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017
Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017
Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017Drew Madelung
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound IntegrationsSujit Kumar
 
Power Automate Techniques that "Saved Our Bacon"
Power Automate Techniques that "Saved Our Bacon"Power Automate Techniques that "Saved Our Bacon"
Power Automate Techniques that "Saved Our Bacon"Thomas Duff
 
Quick start guide to java script frameworks for sharepoint add ins sharepoint...
Quick start guide to java script frameworks for sharepoint add ins sharepoint...Quick start guide to java script frameworks for sharepoint add ins sharepoint...
Quick start guide to java script frameworks for sharepoint add ins sharepoint...Sonja Madsen
 
Muleesbcomponents1 160625154208
Muleesbcomponents1 160625154208Muleesbcomponents1 160625154208
Muleesbcomponents1 160625154208ppts123456
 
Design and Development performance considerations
Design and Development performance considerationsDesign and Development performance considerations
Design and Development performance considerationsElaine Van Bergen
 
Tuning Sql Server for SharePoint--- Community Day Belgium 2013
Tuning Sql Server for SharePoint--- Community Day Belgium 2013Tuning Sql Server for SharePoint--- Community Day Belgium 2013
Tuning Sql Server for SharePoint--- Community Day Belgium 2013Isabelle Van Campenhoudt
 
Building RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPIBuilding RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPIGert Drapers
 
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...BIWUG
 
PV Standard Search Query
PV Standard Search QueryPV Standard Search Query
PV Standard Search QueryProdigyView
 
SUGUK Cambridge - Display Templates & JSLink for IT Pros
SUGUK Cambridge - Display Templates & JSLink for IT ProsSUGUK Cambridge - Display Templates & JSLink for IT Pros
SUGUK Cambridge - Display Templates & JSLink for IT ProsPaul Hunt
 
Advancing Your Custom Fields - WordCamp 2014
Advancing Your Custom Fields - WordCamp 2014Advancing Your Custom Fields - WordCamp 2014
Advancing Your Custom Fields - WordCamp 2014Carleton Web Services
 

Similar a Parsing strange v4 (20)

The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
 
PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptx
 
Wordpress theme development
Wordpress theme developmentWordpress theme development
Wordpress theme development
 
&lt;?php + WordPress
&lt;?php + WordPress&lt;?php + WordPress
&lt;?php + WordPress
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
 
Power Automate Techniques that "Save
Power Automate Techniques that "SavePower Automate Techniques that "Save
Power Automate Techniques that "Save
 
Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017
Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017
Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound Integrations
 
Power Automate Techniques that "Saved Our Bacon"
Power Automate Techniques that "Saved Our Bacon"Power Automate Techniques that "Saved Our Bacon"
Power Automate Techniques that "Saved Our Bacon"
 
Practical OData
Practical ODataPractical OData
Practical OData
 
Quick start guide to java script frameworks for sharepoint add ins sharepoint...
Quick start guide to java script frameworks for sharepoint add ins sharepoint...Quick start guide to java script frameworks for sharepoint add ins sharepoint...
Quick start guide to java script frameworks for sharepoint add ins sharepoint...
 
Muleesbcomponents1 160625154208
Muleesbcomponents1 160625154208Muleesbcomponents1 160625154208
Muleesbcomponents1 160625154208
 
Design and Development performance considerations
Design and Development performance considerationsDesign and Development performance considerations
Design and Development performance considerations
 
Tuning Sql Server for SharePoint--- Community Day Belgium 2013
Tuning Sql Server for SharePoint--- Community Day Belgium 2013Tuning Sql Server for SharePoint--- Community Day Belgium 2013
Tuning Sql Server for SharePoint--- Community Day Belgium 2013
 
Building RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPIBuilding RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPI
 
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
SharePoint Saturday Belgium 2014 - Using JSLink and Display Templates with th...
 
PV Standard Search Query
PV Standard Search QueryPV Standard Search Query
PV Standard Search Query
 
SUGUK Cambridge - Display Templates & JSLink for IT Pros
SUGUK Cambridge - Display Templates & JSLink for IT ProsSUGUK Cambridge - Display Templates & JSLink for IT Pros
SUGUK Cambridge - Display Templates & JSLink for IT Pros
 
Advancing Your Custom Fields - WordCamp 2014
Advancing Your Custom Fields - WordCamp 2014Advancing Your Custom Fields - WordCamp 2014
Advancing Your Custom Fields - WordCamp 2014
 

Último

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Último (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Parsing strange v4

  • 1. © 2010 Hal Stern Some Rights Reserved Parsing Strange: URL to SQL to HTML Hal Stern snowmanonfire.com slideshare.net/freeholdhal headshot by Richard Stevens http://dieselsweeties.com
  • 2. © 2010 Hal Stern Some Rights Reserved Why Do You Care? • Database performance = user experience • A little database expertise goes a long way • Taxonomies for more than sidebar lists • Custom post types • WordPress as a powerful CMS >> blog > Change default behaviors > Defy the common wisdom > Integrate other content sources/filters WordCamp Philly 2010 2
  • 3. © 2010 Hal Stern Some Rights Reserved 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 3WordCamp Philly 2010
  • 4. © 2010 Hal Stern Some Rights Reserved Whose File Is This? • User URL request passed to web server • Web server checks .htaccess file > WP install root > Other .htaccess files may interfere • Basic rewriting rules: If file or directory URL doesn’t exist, start WordPress via index.php WordCamp Philly 2010 4 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /whereyouputWordPress/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
  • 5. © 2010 Hal Stern Some Rights Reserved Example Meta Fail: 404 Not Found • Access broken image URLs for unintended results: no 404 pages! myblog/images/not-a-pic.jpg • Web server can’t find file, assumes it’s a permalink, hands to WP • WP can’t interpret it, so defaults to home WordCamp Philly 2010 5 myblog/ myblog/wp-content (etc) myblog/images
  • 6. © 2010 Hal Stern Some Rights Reserved What Happens Before The Loop • Parse URL into a query • Set conditionals & select templates • Execute the query & cache results • Run the Loop: <?php if (have_posts()) : while (have_posts()) : the_post(); //loop content endwhile; endif; ?> WordCamp Philly 2010 6
  • 7. © 2010 Hal Stern Some Rights Reserved Examining the Query String • SQL passed to MySQL in WP_Query object’s request element • Brute force: edit theme footer.php to see main loop’s query for displayed page WordCamp Philly 2010 7 <?php global $wp_query; echo ”SQL for this page "; echo $wp_query->request; echo "<br>"; ?>
  • 8. © 2010 Hal Stern Some Rights Reserved “Home Page” Query Deconstruction WordCamp Philly 2010 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' OR wp_posts.post_status = 'private’) ORDER BY wp_posts.post_date DESC LIMIT 0, 10 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. © 2010 Hal Stern Some Rights Reserved 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” > Match custom post type slugs WordCamp Philly 2010 9
  • 10. © 2010 Hal Stern Some Rights Reserved 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 • post_type variable has been around for a while; CPT queries fill in new values WordCamp Philly 2010 10
  • 11. © 2010 Hal Stern Some Rights Reserved Simple Title Slug Parsing • Rewrite matches root of permalink, extracts tail of URL as a title slug WordCamp Philly 2010 11 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 /2010/premio-sausage
  • 12. © 2010 Hal Stern Some Rights Reserved CPT Query Variables • Register CPT with a custom query variable 'query_var' => 'ebay' • Variable works in URLs like built-ins myblog.com/?ebay=current_items myblog.com/?ebay=cool_searches • Variable value matches CPT title slug WordCamp Philly 2010 12
  • 13. © 2010 Hal Stern Some Rights Reserved WordPress Meta Data • Common DB mechanics for all meta data > Categories, tags, custom taxonomies • Normalized down to 3 tables > Terms: word strings and their slugs > Taxonomies: collections of terms > Relationships: terms attached to posts • It’s so simple it gets really complex. Really. WordCamp Philly 2010 13
  • 14. © 2010 Hal Stern Some Rights Reserved Graphs and JOIN Operations • WordPress maps tags and categories 1:N to posts (each term in many posts) • You need to punch MySQL to handle hierarchical, multi-valued relations > INNER JOIN builds intermediate tables on common key values • Following link in a graph is equivalent to an INNER JOIN on tables of linked items WordCamp Philly 2010 14
  • 15. © 2010 Hal Stern Some Rights Reserved WordPress Taxonomy Tables • Term relationships table maps N terms to each post • Term taxonomy maps N terms to each taxonomy • Term table has slugs for URL mapping WordCamp Philly 2010 15 wp_term_relationships object_id term_taxonomy_id wp_posts post_id …. post_date … post_content wp_term_taxonomy term_taxonomy_id term_id taxonomy description wp_terms term_id name slug
  • 16. © 2010 Hal Stern Some Rights Reserved SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER 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 Philly 2010 16 /tag/premio
  • 17. © 2010 Hal Stern Some Rights Reserved 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 Philly 2010 17
  • 18. © 2010 Hal Stern Some Rights Reserved 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 Philly 2010 18
  • 19. © 2010 Hal Stern Some Rights Reserved SQL Generation Filters • posts_where > More explicit control over query variable to SQL grammar mapping • posts_join > Add or modify JOIN operations for other graph relationships • Many other filters > Change grouping of results > Change ordering of results WordCamp Philly 2010 19
  • 20. © 2010 Hal Stern Some Rights Reserved Custom Post Types • Change SQL WHERE clause on post type > wp_posts.post_type=‘ebay’ • Add new rewrite rules for URL parsing similar to category & tag > Set slug in CPT registration array 'rewrite' => array ("slug" => “ebay”) • Watch out for competing, overwritten or unflushed rewrite entries <?php echo "<pre>”; print_r(get_option('rewrite_rules')); echo "</pre>”; ?> WordCamp Philly 2010 20
  • 21. © 2010 Hal Stern Some Rights Reserved Applications • Stylized listings > Category sorted alphabetically > Use posts as listings of resources (jobs, clients, events) – use CPT for more control • Custom URL slugs > Add rewrite rules to match slug and set query variables • Joining other social graphs > Suggested/related content WordCamp Philly 2010 21
  • 22. © 2010 Hal Stern Some Rights Reserved 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_redirect action > Called in the template loader > Add actions to override defaults WordCamp Philly 2010 22
  • 23. © 2010 Hal Stern Some Rights Reserved 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 Philly 2010 23
  • 24. © 2010 Hal Stern Some Rights Reserved More Complex Example • For category or tag templates, intersperse custom post types into the results, sorting by post date or alphabetically by title. • Attach filter to posts_where: if (query is for a category or tag) $where = ‘(‘ . $where . ‘)’ . “OR post_type=‘extras’” ; • This changes the database query….. WordCamp Philly 2010 24
  • 25. © 2010 Hal Stern Some Rights Reserved Matching Tags • What if you want to match tags from user- selected posts to tagged CPT posts? • Need to get the list of tags from the main loop query • In template, create a new query looking for post_type=‘cpt type’ • Use JOIN to match collected tags to tags in the CPT (or other custom) taxonomy WordCamp Philly 2010 25
  • 26. © 2010 Hal Stern Some Rights Reserved Why Do You Care? • User experience improvement > JOINS are expensive > Large post 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 Philly 2010 26
  • 27. © 2010 Hal Stern Some Rights Reserved Resources • Core files where SQL stuff happens > query.php > post.php > canonical.php > rewrite.php • Template loader search path > http://codex.wordpress.org/Template_Hierarchy WordCamp Philly 2010 27
  • 28. © 2010 Hal Stern Some Rights Reserved Contact (Shameless Plug) Hal Stern freeholdhal@gmail.com @freeholdhal snowmanonfire.com facebook.com/hal.stern slideshare.net/freeholdhal WordCamp Philly 2010 28

Notas del editor

  1. yesterday – UX, URLs are your currency it’s how the world sees us, and gives us incredible flexibility to direct/guide users
  2. 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 case Type=post versus revision; status publish/private versus draft, trash
  3. 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
  4. You can
  5. Separate namespaces for pages and posts What about parent pages? In this example the permalink structure is %year%/%title%
  6. 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 in Get 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_relationships Order the final table by post date,starting with the most recent (0) and getting 10 of them.
  7. Don’t want multiple URLs pointing to the same page, so canonical parsing cleans them up