Skip to content

Commit 16591ea

Browse files
committed
Update custom tax permalinks
1 parent 0a755c3 commit 16591ea

6 files changed

Lines changed: 88 additions & 20 deletions

File tree

plugins/osi-features/inc/classes/class-rewrite.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
namespace Osi\Features\Inc;
99

1010
use Osi\Features\Inc\Traits\Singleton;
11+
use Osi\Features\Inc\Post_Types\Post_Type_Board_Member;
12+
use Osi\Features\Inc\Taxonomies\Taxonomy_Status;
13+
use Osi\Features\Inc\Post_Types\Post_Type_License;
14+
use Osi\Features\Inc\Taxonomies\Taxonomy_License_Category;
15+
use Osi\Features\Inc\Post_Types\Post_Type_Press_Mentions;
16+
use Osi\Features\Inc\Taxonomies\Taxonomy_Publication;
17+
use Osi\Features\Inc\Taxonomies\Taxonomy_Seat_Type;
18+
use Osi\Features\Inc\Taxonomies\Taxonomy_Steward;
1119

1220
/**
1321
* Class Rewrite
@@ -32,6 +40,7 @@ protected function __construct() {
3240
*/
3341
protected function setup_hooks() {
3442
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 10 );
43+
add_action( 'init', [ $this, 'add_custom_rewrite_rules' ], 20 );
3544
}
3645

3746
public function add_query_vars( $vars ) {
@@ -40,4 +49,48 @@ public function add_query_vars( $vars ) {
4049
return $vars;
4150
}
4251

52+
/**
53+
* Add custom rewrite rules for custom post types and taxonomies.
54+
*
55+
* @return void
56+
*/
57+
public function add_custom_rewrite_rules() {
58+
$base = Post_Type_License::get_instance()->get_slug();
59+
add_rewrite_rule(
60+
'^' . $base . '/steward/([^/]+)/?$',
61+
'index.php?taxonomy=' . Taxonomy_Steward::SLUG . '&term=$matches[1]',
62+
'top'
63+
);
64+
65+
$base = Post_Type_Board_Member::get_instance()->get_slug();
66+
add_rewrite_rule(
67+
'^' . $base . '/status/([^/]+)/?$',
68+
'index.php?taxonomy=' . Taxonomy_Status::SLUG . '&term=$matches[1]',
69+
'top'
70+
);
71+
72+
$base = Post_Type_Board_Member::get_instance()->get_slug();
73+
add_rewrite_rule(
74+
'^' . $base . '/seat-type/([^/]+)/?$',
75+
'index.php?taxonomy=' . Taxonomy_Seat_Type::SLUG . '&term=$matches[1]',
76+
'top'
77+
);
78+
79+
$base = Post_Type_License::get_instance()->get_slug();
80+
add_rewrite_rule(
81+
'^' . $base . '/category/([^/]+)/?$',
82+
'index.php?taxonomy=' . Taxonomy_License_Category::SLUG . '&term=$matches[1]',
83+
'top'
84+
);
85+
86+
$base = Post_Type_Press_Mentions::get_instance()->get_slug();
87+
add_rewrite_rule(
88+
'^' . $base . '/publication/([^/]+)/?$',
89+
'index.php?taxonomy=' . Taxonomy_Publication::SLUG . '&term=$matches[1]',
90+
'top'
91+
);
92+
93+
94+
}
95+
4396
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-license-category.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71-
72-
return wp_parse_args(
71+
72+
return wp_parse_args(
7373
[
74-
'rewrite' => array( 'slug' => 'license-category' ),
75-
],
74+
'rewrite' => [
75+
'slug' => Post_Type_License::get_instance()->get_slug() . '/category',
76+
'with_front' => false,
77+
],
78+
],
7679
parent::get_args()
7780
);
7881
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-publication.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71-
72-
return wp_parse_args(
71+
72+
return wp_parse_args(
7373
[
7474
'hierarchical' => true,
75-
'rewrite' => array( 'slug' => 'publication' ),
76-
],
75+
'rewrite' => [
76+
'slug' => Post_Type_Press_Mentions::get_instance()->get_slug() . '/publication',
77+
'with_front' => false,
78+
],
79+
],
7780
parent::get_args()
7881
);
7982
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-seat-type.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71-
72-
return wp_parse_args(
71+
72+
return wp_parse_args(
7373
[
7474
'hierarchical' => false,
75-
'rewrite' => array( 'slug' => 'seat-type' ),
76-
],
75+
'rewrite' => [
76+
'slug' => Post_Type_Board_Member::get_instance()->get_slug() . '/seat-type',
77+
'with_front' => false,
78+
],
79+
],
7780
parent::get_args()
7881
);
7982
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-status.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71-
72-
return wp_parse_args(
71+
72+
return wp_parse_args(
7373
[
7474
'hierarchical' => false,
75-
'rewrite' => array( 'slug' => 'status' ),
76-
],
75+
'rewrite' => [
76+
'slug' => Post_Type_Board_Member::get_instance()->get_slug() . '/status',
77+
'with_front' => false,
78+
],
79+
],
7780
parent::get_args()
7881
);
7982
}

plugins/osi-features/inc/classes/taxonomies/class-taxonomy-steward.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ public function get_post_types() {
6868
* @return array
6969
*/
7070
public function get_args() {
71-
72-
return wp_parse_args(
71+
72+
return wp_parse_args(
7373
[
7474
'hierarchical' => false,
75-
'rewrite' => array( 'slug' => 'steward' ),
76-
],
75+
'rewrite' => [
76+
'slug' => Post_Type_License::get_instance()->get_slug() . '/steward',
77+
'with_front' => false,
78+
],
79+
],
7780
parent::get_args()
7881
);
7982
}

0 commit comments

Comments
 (0)