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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.