Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. /service_locations/city-name/
  2.  
  3. /serivce_locations/city-name/service-type/
  4.  
  5. add_action( 'init', 'service_locations' );
  6. function service_locations() {
  7. register_post_type('service_locations', array(
  8. 'label' => 'Service Areas',
  9. 'description' => '',
  10. 'public' => true,
  11. 'show_ui' => true,
  12. 'show_in_menu' => true,
  13. 'capability_type' => 'post',
  14. 'hierarchical' => true,
  15. 'rewrite' => true,
  16. 'query_var' => true,
  17. 'exclude_from_search ' => true,
  18. 'has_archive' => true,
  19. 'supports' => array(
  20. 'title',
  21. 'page-attributes'
  22. ),
  23. )
  24. );
  25. }
  26.  
  27. /city-name/
  28.  
  29. /city-name/service-type/
  30.  
  31. // Remove the slug from published post permalinks. Only affect our CPT though.
  32. function vipx_remove_cpt_slug( $post_link, $post, $leavename ) {
  33. if ( ! in_array( $post->post_type, array( 'service_locations' ) ) || 'publish' != $post->post_status )
  34. return $post_link;
  35. $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
  36. return $post_link;
  37. }
  38. add_filter( 'post_type_link', 'vipx_remove_cpt_slug', 10, 3 );
  39.  
  40. function vipx_parse_request_tricksy( $query ) {
  41. if ( ! $query->is_main_query() )
  42. return;
  43.  
  44. if ( 2 != count( $query->query )
  45. || ! isset( $query->query['page'] ) )
  46. return;
  47.  
  48. if ( ! empty( $query->query['name'] ) )
  49. $query->set( 'post_type', array( 'post', 'service_locations', 'page' ) );
  50. }
  51. add_action( 'pre_get_posts', 'vipx_parse_request_tricksy' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement