diff --git a/includes/Permalink.php b/includes/Permalink.php index 83923d1..20b84b9 100644 --- a/includes/Permalink.php +++ b/includes/Permalink.php @@ -47,12 +47,19 @@ public function add_hooks() { */ public function post_type_link( $post_link, \WP_Post $post ) { - if ( ! $this->option->get_structure( $post->post_type ) ) { + $post_type = $post->post_type; + if ( ! $this->option->get_structure( $post_type ) ) { return $post_link; } - $rewritecode = array( "%{$post->post_type}_id%", ); - $rewritereplace = array( $post->ID, ); + $rewritecode = array( + "%${post_type}_slug%", + "%post_id%", + ); + $rewritereplace = array( + $this->option->get_front_struct( $post_type ), + $post->ID, + ); return str_replace( $rewritecode, $rewritereplace, $post_link ); diff --git a/includes/Rewrite.php b/includes/Rewrite.php index c1b10ff..24c9349 100644 --- a/includes/Rewrite.php +++ b/includes/Rewrite.php @@ -99,17 +99,26 @@ public function register_rewrite_rule( $post_type, $args ) { $permastruct_args = $args->rewrite; $permastruct_args['feed'] = $permastruct_args['feeds']; - $queryarg = "post_type={$post_type}&p="; - $tag = "%{$post_type}_id%"; - - add_rewrite_tag( $tag, '([0-9]+)', $queryarg ); if ( $struct = $this->option->get_structure( $post_type ) ) { - $search = array( '%postname%', '%post_id%' ); - $replace = array( "%{$post_type}%", "%{$post_type}_id%" ); - $struct = str_replace( $search, $replace, $struct ); + //$post_type_slug = $args->rewrite['slug']; + $post_type_slug = $this->option->get_front_struct( $post_type ); + add_rewrite_tag( "%${post_type}_slug%", "(${post_type_slug})", "post_type=${post_type}&slug=" ); + + $struct = str_replace( + array( + $post_type_slug, + '%postname%', + + ), + array( + "%${post_type}_slug%", + "%{$post_type}%", + ), + $struct ); + //$rewrite_args['walk_dirs'] = false; add_permastruct( $post_type, $struct, $permastruct_args ); $slug = $this->option->get_front_struct( $post_type );