-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrewrite-sample.php
More file actions
69 lines (49 loc) · 2.64 KB
/
rewrite-sample.php
File metadata and controls
69 lines (49 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
//Sample 1
function newwhello_rewriteRules( $rules ) {
$new_rules = array(
'online-marketing-specialist/(.+?)/([^/]+)(?:/([0-9]+))?/?$' => 'post_type=specialist&cat_specialist=$matches[1]&specialist=$matches[2]&page=$matches[3]',
'(marketing-tips)/page/?([0-9]{1,})/?$' => 'pagename=$matches[1]&paged=$matches[2]',
'marketing-tips/(.+?)/page/?([0-9]{1,})/?$' => 'post_type=post&category_name=$matches[1]&paged=$matches[2]',
'marketing-tips/(.+?)/([^/]+)(?:/([0-9]+))?/?$' => 'post_type=post&category_name=$matches[1]&name=$matches[2]&page=$matches[3]',
'blog/(.+?)/page/?([0-9]{1,})/?$' => 'category_name=$matches[1]&paged=$matches[2]',
'(blog)/page/?([0-9]{1,})/?$' => 'pagename=$matches[1]&paged=$matches[2]',
'blog/(.+?)/([^/]+)(?:/([0-9]+))?/?$' => 'category_name=$matches[1]&name=$matches[2]&page=$matches[3]',
'succesverhalen/(.+?)/page/?([0-9]{1,})/?$' => 'cat_succesverhalen=$matches[1]&paged=$matches[2]',
'(succesverhalen)/page/?([0-9]{1,})/?$' => 'pagename=$matches[1]&paged=$matches[2]',
// 'media/([^/]+)/([^/]+)(?:/([0-9]+))?/?$' => 'cat_media=$matches[1]&name=$matches[2]&page=$matches[3]',
);
return $new_rules + $rules;
}
add_action( 'rewrite_rules_array', 'newwhello_rewriteRules' );
//Sample 2 using class
class WhelloRewriteRules {
function __construct() {
add_action('generate_rewrite_rules', array( $this, 'rewrite_rules'), 99 );
//add_filter( 'query_vars', array( $this, 'prefix_register_query_var') );
}
public function rewrite_rules($wp_rewrite){
global $wp_rewrite;
$rules = array();
$base = "marketing-voorbeelden";
$lokasi = get_terms( array( 'taxonomy' => 'cases', 'hide_empty' => false ));
$rules[$base . '/page/?([0-9]{1,})/?$'] = 'index.php?pagename='.$base.'&paged=$matches[1]';
$rules[$base . '/?$'] = 'index.php?pagename='.$base;
foreach($lokasi as $term) {
$rules[$base . '/' . $term->slug . '/page/?([0-9]{1,})/?$'] = 'index.php?pagename='.$base.'&cases='.$term->slug.'&paged=$matches[1]';
$rules[$base . '/' . $term->slug . '/([^/]+)(?:/([0-9]+))?/?$'] = 'index.php?cases=$matches[1]';
$rules[$base . '/' . $term->slug . '/?$'] = 'index.php?pagename='.$base.'&cases='.$term->slug;
}
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
return $wp_rewrite->rules;
}
}
new WhelloRewriteRules;
//remove spesific string in url
function __custom_messagetypes_link( $link, $term, $taxonomy )
{
if ( $taxonomy !== 'cases' )
return $link;
return str_replace( 'marketing-tips/', '', $link );
}
add_filter( 'term_link', '__custom_messagetypes_link', 10, 3 );