Skip to content

Commit

Permalink
use %post_id%
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed Aug 11, 2016
1 parent a45b658 commit 7c840bd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
13 changes: 10 additions & 3 deletions includes/Permalink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
23 changes: 16 additions & 7 deletions includes/Rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 7c840bd

Please sign in to comment.