Jump to content

Help With Url Rewrite Wordpress


deg

Recommended Posts

In the below function I am trying to understand the $new_rules array. I understand it is matching a pattern an then rewriting that pattern to a friendly url.

 

But I just don't understand the logic of what portion is capturing the pattern and what portion is telling it to rewrite in another format and what that format is.

 

Could someone help me understand each section of the $new_array in basic terms so I can understand the logic of the matching and rewrite?

 

I am trying to learn this but just can seem to get it.

 

In this example cardealers is my custom post type, and brands and state are a taxonomy.

 

Thank you!

 

function eg_add_rewrite_rules() {
global $wp_rewrite;[/font][/color]
$new_rules = array(
'cardealers/(brands|state)/(.+?)/(brands|state)/(.+?)/?$' => 'index.php?post_type=cardealers&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2) . '&' . $wp_rewrite->preg_index(3) . '=' . $wp_rewrite->preg_index(4),
'cardealers/(brands|state)/(.+)/?$' => 'index.php?post_type=cardealers&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
add_action( 'generate_rewrite_rules', 'eg_add_rewrite_rules' );

Link to comment
https://forums.phpfreaks.com/topic/271472-help-with-url-rewrite-wordpress/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.