Slide 1

Slide 1 text

What’s in a WordPress Web Address Simon Wheatley (@simonwheatley) https://www.flickr.com/photos/carolynwillitts/3156518827/in/set-72157611966344355

Slide 2

Slide 2 text

We have a problem https://www.flickr.com/photos/adactio/5730227336

Slide 3

Slide 3 text

Who are you?

Slide 4

Slide 4 text

I work at WordPress.com VIP

Slide 5

Slide 5 text

Cool URIs are important http://www.flickr.com/photos/knightfoundation/2858604501/sizes/o/

Slide 6

Slide 6 text

Pretty URLs since 2003

Slide 7

Slide 7 text

ouragency.com/2015/03/hello-world/

Slide 8

Slide 8 text

ouragency.com/worked-for/dyson/

Slide 9

Slide 9 text

ouragency.com/worked-for/dyson/json/

Slide 10

Slide 10 text

ouragency.com/compare/dyson+hoover+vax/

Slide 11

Slide 11 text

ouragency.com/2015/03/hello-world/

Slide 12

Slide 12 text

Get the post Posted in March 2015
 With a slug of “hello-world”

Slide 13

Slide 13 text

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND ( ( YEAR( wp_posts.post_date ) = 2015 AND MONTH( wp_posts.post_date ) = 3 ) ) AND wp_posts.post_name = 'hello-world' AND wp_posts.post_type = 'post' ORDER BY wp_posts.post_date DESC

Slide 14

Slide 14 text

ouragency.com/?year=2015&monthnum=03&name=hello-world

Slide 15

Slide 15 text

ouragency.com/2015/03/hello-world/

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

ouragency.com/2015/03/hello-world/ ([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$
 
 index.php?
 year=$matches[1]&
 monthnum=$matches[2]&
 name=$matches[3]&
 page=$matches[4]

Slide 18

Slide 18 text

ouragency.com/2015/03/hello-world/ ([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$
 
 index.php?
 year=$matches[1]&
 monthnum=$matches[2]&
 name=$matches[3]&
 page=$matches[4]

Slide 19

Slide 19 text

ouragency.com/2015/03/hello-world/ ([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$
 
 index.php?
 year=$matches[1]&
 monthnum=$matches[2]&
 name=$matches[3]&
 page=$matches[4]

Slide 20

Slide 20 text

ouragency.com/2015/03/hello-world/ ([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$
 
 index.php?
 year=$matches[1]&
 monthnum=$matches[2]&
 name=$matches[3]&
 page=$matches[4]

Slide 21

Slide 21 text

ouragency.com/2015/03/hello-world/ ([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$
 
 index.php?
 year=$matches[1]&
 monthnum=$matches[2]&
 name=$matches[3]&
 page=$matches[4]

Slide 22

Slide 22 text

ouragency.com/2015/03/hello-world/2/ ([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$
 
 index.php?
 year=$matches[1]&
 monthnum=$matches[2]&
 name=$matches[3]&
 page=$matches[4]

Slide 23

Slide 23 text

ouragency.com/2015/03/hello-world/

Slide 24

Slide 24 text

Custom Post Types and Taxonomies https://www.flickr.com/photos/beate_meier/8337014543

Slide 25

Slide 25 text

ouragency.com/work-for/dyson/

Slide 26

Slide 26 text

$rewrite = array( 'slug' => ‘worked-for‘, ); $args = array( 'labels' => $labels, 'has_archive' => 'our-work', 'public' => true, 'menu_icon' => 'dashicons-blahs', 'rewrite' => $rewrite, ); register_post_type( 'sw_team', $args );

Slide 27

Slide 27 text

ouragency.com/work-for/dyson/

Slide 28

Slide 28 text

ouragency.com/work-for/dyson/

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

ouragency.com/work-for/([^/]+)(/[0-9]+)?/?$ 
 index.php?sw_client=$1&page=$2

Slide 31

Slide 31 text

ouragency.com/work-for/([^/]+)(/[0-9]+)?/?$ 
 index.php?sw_client=$1&page=$2

Slide 32

Slide 32 text

ouragency.com/work-for/([^/]+)(/[0-9]+)?/?$ 
 index.php?sw_client=$1&page=$2

Slide 33

Slide 33 text

ouragency.com/work-for/([^/]+)(/[0-9]+)?/?$ 
 index.php?sw_client=$1&page=$2

Slide 34

Slide 34 text

ouragency.com/work-for/([^/]+)(/[0-9]+)?/?$ 
 index.php?sw_client=$1&page=$2

Slide 35

Slide 35 text

Get all the posts
 Where the post type is “sw_client”
 And the name of the posts are “dyson”


Slide 36

Slide 36 text

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_name = '$1' AND wp_posts.post_type = 'sw_client' ORDER BY wp_posts.post_date DESC

Slide 37

Slide 37 text

Endpoints https://www.flickr.com/photos/nhankamer/5525695925

Slide 38

Slide 38 text

ouragency.com/work-for/dyson/feed/rdf/

Slide 39

Slide 39 text

ouragency.com/work-for/dyson/feed/rss/

Slide 40

Slide 40 text

ouragency.com/work-for/dyson/json/

Slide 41

Slide 41 text

add_rewrite_endpoint( 'json', EP_PERMALINK, 'sw_json' );

Slide 42

Slide 42 text

add_rewrite_endpoint( 'json', EP_PERMALINK, 'sw_json' );

Slide 43

Slide 43 text

add_rewrite_endpoint( 'json', EP_PERMALINK, 'sw_json' );

Slide 44

Slide 44 text

add_rewrite_endpoint( 'json', EP_PERMALINK, 'sw_json' );

Slide 45

Slide 45 text

ouragency.com/work-for/dyson/format/json/

Slide 46

Slide 46 text

ouragency.com/are/dyson/format/json/

Slide 47

Slide 47 text

ouragency.com/work-for/dyson/format/json/

Slide 48

Slide 48 text

// Called on request filter function sw_fix_endpoint_reqs( $vars ) { if ( isset( $vars['sw_json'] ) ) { $vars['sw_json'] = true; } return $vars; }

Slide 49

Slide 49 text

if ( get_query_var( ‘sw_json’ ) ) { 
 // Done some stuff, switch content, etc }

Slide 50

Slide 50 text

Custom Rewrite Rules https://www.flickr.com/photos/xiaming/314772076

Slide 51

Slide 51 text

ouragency.com/compare/dyson+hoover+vax/

Slide 52

Slide 52 text

add_rewrite_rule(
 'compare/([^/]+)/?$', 'index.php?sw_compare=$matches[1]' );

Slide 53

Slide 53 text

add_rewrite_rule(
 'compare/([^/]+)/?$', 'index.php?sw_compare=$matches[1]' );

Slide 54

Slide 54 text

add_rewrite_rule(
 'compare/([^/]+)/?$', 'index.php?sw_compare=$matches[1]' );

Slide 55

Slide 55 text

// Called on request filter
 $names_to_compare = explode( '+', $vars['sw_compare'] ); foreach ( $names_to_compare as $name ) { $args = array( 'post_type' => 'sw_client', 'name' => $name, 'fields' => 'ids', ); $query = new WP_Query( $args ); $post_ids = array_merge( $query->posts, $post_ids ); } $vars['post__in'] = $post_ids; $vars['post_type'] = 'sw_client';

Slide 56

Slide 56 text

// Called on request filter
 $names_to_compare = explode( '+', $vars['sw_compare'] ); foreach ( $names_to_compare as $name ) { $args = array( 'post_type' => 'sw_client', 'name' => $name, 'fields' => 'ids', ); $query = new WP_Query( $args ); $post_ids = array_merge( $query->posts, $post_ids ); } $vars['post__in'] = $post_ids; $vars['post_type'] = 'sw_client';

Slide 57

Slide 57 text

// Called on request filter
 $names_to_compare = explode( '+', $vars['sw_compare'] ); foreach ( $names_to_compare as $name ) { $args = array( 'post_type' => 'sw_client', 'name' => $name, 'fields' => 'ids', ); $query = new WP_Query( $args ); $post_ids = array_merge( $query->posts, $post_ids ); } $vars['post__in'] = $post_ids; $vars['post_type'] = 'sw_client';

Slide 58

Slide 58 text

// Called on request filter
 $names_to_compare = explode( '+', $vars['sw_compare'] ); foreach ( $names_to_compare as $name ) { $args = array( 'post_type' => 'sw_client', 'name' => $name, 'fields' => 'ids', ); $query = new WP_Query( $args ); $post_ids = array_merge( $query->posts, $post_ids ); } $vars['post__in'] = $post_ids; $vars['post_type'] = 'sw_client';

Slide 59

Slide 59 text

// Called on request filter
 $names_to_compare = explode( '+', $vars['sw_compare'] ); foreach ( $names_to_compare as $name ) { $args = array( 'post_type' => 'sw_client', 'name' => $name, 'fields' => 'ids', ); $query = new WP_Query( $args ); $post_ids = array_merge( $query->posts, $post_ids ); } $vars['post__in'] = $post_ids; $vars['post_type'] = 'sw_client';

Slide 60

Slide 60 text

// Called on request filter
 $names_to_compare = explode( '+', $vars['sw_compare'] ); foreach ( $names_to_compare as $name ) { $args = array( 'post_type' => 'sw_client', 'name' => $name, 'fields' => 'ids', ); $query = new WP_Query( $args ); $post_ids = array_merge( $query->posts, $post_ids ); } $vars['post__in'] = $post_ids; $vars['post_type'] = 'sw_client';

Slide 61

Slide 61 text

if ( get_query_var( ‘sw_compare’ ) ) { 
 // Switch template, show our 3 posts }

Slide 62

Slide 62 text

So, to wrap up... http://www.flickr.com/photos/ejchang/3139547559/in/photostream/

Slide 63

Slide 63 text

ouragency.com/2015/03/hello-world/

Slide 64

Slide 64 text

ouragency.com/worked-for/dyson/

Slide 65

Slide 65 text

ouragency.com/worked-for/dyson/json/

Slide 66

Slide 66 text

ouragency.com/compare/dyson+hoover+vax/

Slide 67

Slide 67 text

© Christian Senger - https://www.flickr.com/photos/30928442@N08/6343274075 A regular expressions explorer

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

Rewrite Rules Inspector https://www.flickr.com/photos/tlang/2703769775

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

https://www.flickr.com/photos/liverpoolhls/10740309163 Query Monitor

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

http://j.mp/sw-wcldn-15/

Slide 76

Slide 76 text

Work at WordPress.com VIP
 http://j.mp/sw-vip-job

Slide 77

Slide 77 text

Questions http://www.flickr.com/photos/38299630@N05/3635356091/sizes/o/

Slide 78

Slide 78 text

Work at WordPress.com VIP
 http://j.mp/sw-vip-job (http://automattic.com/work-with-us/vip-wrangler/)