Advertisement
Guest User

Untitled

a guest
Sep 10th, 2014
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. if( !function_exists( 'mars_remove_cpt_slug' ) ){
  2.     /**
  3.      * Remove the slug from published post permalinks. Only affect our CPT though.
  4.      */
  5.     function mars_remove_cpt_slug( $post_link, $post, $leavename ) {
  6.    
  7.         if ( ! in_array( $post->post_type, array( 'video' ) ) || 'publish' != $post->post_status )
  8.             return $post_link;
  9.    
  10.         $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
  11.    
  12.         return $post_link;
  13.     }
  14.     add_filter( 'post_type_link', 'mars_remove_cpt_slug', 10, 3 ); 
  15. }
  16.  
  17. if( !function_exists( 'mars_parse_request' ) ){
  18.     function mars_parse_request( $query ) {
  19.    
  20.         // Only noop the main query
  21.         if ( ! $query->is_main_query() )
  22.             return;
  23.    
  24.         // Only noop our very specific rewrite rule match
  25.         if ( 2 != count( $query->query )
  26.                 || ! isset( $query->query['page'] ) )
  27.             return;
  28.    
  29.         // 'name' will be set if post permalinks are just post_name, otherwise the page rule will match
  30.         if ( ! empty( $query->query['name'] ) )
  31.             $query->set( 'post_type', array( 'post', 'video', 'page' ) );
  32.     }
  33.     add_action( 'pre_get_posts', 'mars_parse_request' );
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement