Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

walk_dirs arg for add_permastruct() #52

Open
ssnepenthe opened this issue Jun 22, 2016 · 3 comments
Open

walk_dirs arg for add_permastruct() #52

ssnepenthe opened this issue Jun 22, 2016 · 3 comments

Comments

@ssnepenthe
Copy link

It looks like you are currently calling add_permastruct without setting $args['walk_dirs'] which means you end up using the core default of true.

Because of this, when setting a permastruct like /slug/%year%/%monthnum%/%postname% you also get the following rules:

slug/([0-9]{4})/([0-9]{1,2})/?$ - index.php?year=$matches[1]&monthnum=$matches[2] - slug
slug/([0-9]{4})/?$ - index.php?year=$matches[1] - slug

While it would be great to have date based archives for custom post types, we are not actually setting the post_type query var so we end up with a second URL where we can view the date archives for the core post post-type.

I don't see an easy way to force the post_type query variable short of filtering $this->post_type . '_rewrite_rules' and manually modifying it (though admittedly I am not very familiar with the rewrite API).

Anyway - I guess I am wondering what your thoughts are about all of this? At a minimum, I would think it would be beneficial to set $this->defaults['rewrite']['walk_dirs'] to false to avoid duplicate content.

At the same time, it would be great to further mimic some of the core functionality such as date based archives when the user sets a permastruct which includes date and time rewrite tags.

@johnbillion
Copy link
Owner

Thanks!

It's been a long while since I implemented a post type that used any of the date parameters in its permastructure, so it's likely that I missed this.

I think it would be expected behaviour that if your post type permastructure includes dates then the corresponding date archives are also available. I'll have a look into this when I have some free time to work on it.

@johnbillion johnbillion added this to the Future milestone Jun 22, 2016
@ssnepenthe
Copy link
Author

By manually setting walk_dirs to false, I realized that the example I provided above actually generates an extra 12 rewrite rules:

+  'slug/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]',
+  'slug/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]',
+  'slug/([0-9]{4})/([0-9]{1,2})/embed/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&embed=true',
+  'slug/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]',
+  'slug/([0-9]{4})/([0-9]{1,2})/comment-page-([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&cpage=$matches[3]',
+  'slug/([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]',
+  'slug/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&feed=$matches[2]',
+  'slug/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&feed=$matches[2]',
+  'slug/([0-9]{4})/embed/?$' => 'index.php?year=$matches[1]&embed=true',
+  'slug/([0-9]{4})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&paged=$matches[2]',
+  'slug/([0-9]{4})/comment-page-([0-9]{1,})/?$' => 'index.php?year=$matches[1]&cpage=$matches[2]',
+  'slug/([0-9]{4})/?$' => 'index.php?year=$matches[1]',

@shadyvb
Copy link

shadyvb commented Aug 11, 2016

This also makes /%category%/... rules break pages permalinks. Setting walk_dirs to false fixed that.

@johnbillion johnbillion removed this from the Future milestone Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants