From Web Address to Web Page – the Humble URL in WordPress

From Web Address to Web Page – the Humble URL in WordPress

Once upon a time we passed parameters to create web pages, now we use pretty URLs and (hopefully) think through our URLs carefully. URLs are one of the fundamental commands a user can give WordPress, and they can be poetic, powerful and precise all at once.

This talk will cover how URLs are turned into WP_Query parameters, what URL endpoints are and when to use them, how URLs can be attractive and amusing, and how to use URLs across different post type structures.

Here's the code I use throughout the presentation, as a plugin to download and slice and dice: https://github.com/simonwheatley/wcldn-web-addresses

947ed080d54e9917ba4dac47fd9c50b2?s=128

Simon Wheatley

March 21, 2015
Tweet

Transcript

  1. 13.

    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
  2. 16.
  3. 26.

    $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 );
  4. 29.
  5. 35.

    Get all the posts
 Where the post type is “sw_client”


    And the name of the posts are “dyson”

  6. 36.

    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
  7. 48.

    // Called on request filter function sw_fix_endpoint_reqs( $vars ) {

    if ( isset( $vars['sw_json'] ) ) { $vars['sw_json'] = true; } return $vars; }
  8. 49.

    if ( get_query_var( ‘sw_json’ ) ) { 
 // Done

    some stuff, switch content, etc }
  9. 55.

    // 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';
  10. 56.

    // 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';
  11. 57.

    // 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';
  12. 58.

    // 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';
  13. 59.

    // 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';
  14. 60.

    // 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';
  15. 68.
  16. 70.
  17. 71.
  18. 73.
  19. 74.