How to create two permalink options for custom post type?
-
Hi all,
I’m trying to create two permalink options for a custom post type called ‘training’.
This custom post type can have multiple grouped custom fields, that have a start date assigned to the group. (a training can have multiple options with their own start/end date)
For this I am using https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/Now, I would like to create the following permalink option:
- http://example.com/trainings/training-post-name (without date) or
- http://example.com/trainings/training-post-name/2014-09-29 (with start date)
So I’ve found a great guide for creating the correct permalinks for custom post types at http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2
However, this doesn’t mention the more advanced option with two permalink options…
Here’s the code I’ve written for this: http://pastebin.com/26We6H0W
The permalink replacement works, but visiting a link with startdate does not work, and I don’t understand why not or how to fix this.This is the function where I am not doing what I should be, I think:
/** * Add support for %postname% and %startdate% tag in permalinks. */ function tr2014_rewrite_tags() { add_rewrite_tag( '%startdate%', '([0-9]{4}-[0-9]{2}-[0-9]{2})$', 'startdate=' ); add_permastruct( 'tr_training', '/trainings/%postname%/%startdate%', false ); add_rewrite_tag( '%postname%', '([^/]+)', 'tr_training=' ); add_permastruct( 'tr_training', '/trainings/%postname%', false ); } add_action( 'init', 'tr2014_rewrite_tags', 10, 0 );
Any help by the advanced WP experts would be greatly appreciated.
- The topic ‘How to create two permalink options for custom post type?’ is closed to new replies.