Here’s an example using add_rewrite_rule
to handle years and months for a custom post type where news
is the slug. Visit the Settings > Permalinks
page in admin to flush rewrite rules after this is added. You could also put this in a plugin and flush rewrite rules on plugin activation.
function wpa83797_news_rewrite_rules(){
add_rewrite_rule(
'news/([0-9]{4})/([0-9]{1,2})/?$',
'index.php?post_type=news&year=$matches[1]&monthnum=$matches[2]',
'top'
);
add_rewrite_rule(
'news/([0-9]{4})/?$',
'index.php?post_type=news&year=$matches[1]',
'top'
);
}
add_action( 'init', 'wpa83797_news_rewrite_rules' );
Related Posts:
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- How to filter custom post type archive by meta value
- Custom post type permalink structure with the category also acting as an archive
- Rewrite custom post type url’s adding meta box values
- Bulk 301 redirect for custom post type
- Custom query variable – get wordpress to redirect to nice permalink url
- Redirecting when changing custom post type slugs?
- Query var removed after rewrite
- CPT Archive with core Category
- Ignoring slug capitalization on rewrite rule for custom post type archive page
- Custom post type archive with page as parent url
- rewriterule not working
- Archive page for custom post type and custom taxonomy
- Custom Post Type Date Based Archive URL rewrite [duplicate]
- How to change URL for custom post type archive?
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- Set archive of custom post type like ‘posts’ page in reading settings is set
- Custom Post Type canonical link / pagination redirecting to root
- Show index and not the archive for “Dog Custom Post” with default slug
- Custom archive URL as a subfolder of the custom post type slug
- How to work with URLs where sometimes a post or a subcategory is in the same part of the URL structure
- Remove date rewrite rule for custom post type archive page
- Rewrite taxonomy permalink appended to CPT archive url
- Rewrites/query for multiple hierarchical custom post types
- Custom Post Type has_archive
- WordPress custom post type split into pages
- cpt and page sharing same base permalink
- Custom Post Type Archive URL is wrong
- WordPress uses url different from defined in rewrite arg of custom post type
- Redirect custom post type category to other custom post type category
- Rewrite URL of Custom Post Type for Jobs
- Creating a Custom Post Type
- Custom post Type, child of a Page?
- Hide or disallow default custom post type url?
- URL rewriting for CTP assigned entity
- Custom Post Type slug same as page name
- How to display custom post in archive section of the wordpress page?
- Content Editable CPT Archive?
- Post Type rewrite rule to point to custom Page/template
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Custom taxonomy returns 404
- list archives per post types
- Canonical url differs from custom post type archive URLs
- Including taxonomy term before post type breaks top level pages
- Display a custom posts page for post type
- Correct procedure for advanced permalinks
- Custom Post Types hierarchy and rewrite
- Custom post type archive pagination 404
- CPT’s with landing page instead of archive – Url Rewrite?
- posttype/taxonomy/term archive page 404 error
- How to get list of taxonomy slugs ordered parents>childs?
- Rewrite rule for Custom Post Type Page as a parent
- Added Custom Post Type and the View Option Doesn’t Work
- Is it possible to have a custom post type with feed but without the archive?
- Rewrite Endpoints and CPTs – How to use in a plugin
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Can slugs from posts and custom post types conflict?
- add_rewrite_rule and passing variables for custom post types
- Pretty URLs and custom post types
- Specific routing for CPT
- Lost of query parameter when using permalink
- Custom post type’s permalink adds the name of the post type before the post name
- Taxonomy in URL
- Custom taxonomy and post type with same slug
- Some posts from custom post type to subdomains
- Custom permalink with child taxonomy terms
- Paginate_links in custom post type template
- My archive-posttype.php template is not loading
- Custom Post Archive is not working
- Limit the Title Length on Custom Post Type Archive Page to a Set Number of Characters
- Add parent post to Custom Post Type [closed]
- Permalink misbehaving in Custom Post Types
- Set featured image to archive.php
- Best way to specify “article type” in URL
- Changed permalink structure of CPT – should I redirect?
- What’s the name of the custom post type yearly archive template?
- Pagination custom post type not working with rewrite slug
- Custom post type, global categories — what’s the template name?
- Custom URL redirect in WP
- Custom Rewrite Rule for Custom Post Type with URL Param
- WordPress custom slug rewrite
- How to hyperlink content from archive page with custom post-type
- Set thumbnail and title for a post type archive (not post itself!)
- How to set up Custom Post Type archive page as Front page
- Url to archive page for custom post type
- Custom URLs in post types make it impossible to view archive
- How can I use archive-{post_type}.php theme template?
- Redirect to archive is single post has a certain term assigned to it?
- How to display CPT archives?
- Custom meta Title for custom post type archive from page
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- Excluding a Custom Post Type with a specific tag using pre_get_posts
- Return the name of the post type
- I can’t access custom taxonomy page listing
- How to have permalink like domain.com/term/postname?
- Redirect to first child on Custom Post Type (without template)
- current-menu-item not added on page showing custom post type (rendered with archive template)
- Alphabetically sort a taxonomy.php template by post title
- Custom Permalinks for Custom Post Types
- post_type_link Filter – Too Few Arguments