It is not necessary to define $wp_rewrite in your function. The add_permastruct() and add_rewrite_rule() functions take care of that for you. Try removing the “global $wp_rewrite;” line and see if your code still works.
The add_permastruct() function currently accepts three parameters. There is some backwards-compatibility logic in the function to correct for calls using the old four-parameter structure, but you might want to change that line to use the current three parameter structure, like this:
add_permastruct( 'news', 'news/%year%/%postname%/', array('with_front' => true, 'ep_mask' => 1) );
Related Posts:
- Can a custom post type have a Parent Page?
- remove custom post type permalink
- Where, When, & How to Properly Flush Rewrite Rules Within the Scope of a Plugin?
- Custom Post Type Permalink / Rewrite not working immediately
- Best way to flush_rewrite_rules for custom post type, in a mu-plugins plugin?
- Custom rewrite rules for archive page and single post
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- Custom post type 404s with rewriting even after resetting permalinks
- Multiple post types – share same ReWrite slug?
- Rewrite rule for Custom post type Monthly and Yearly archive
- Permalink rewrite 404 conflict- WordPress Taxonomies/ CPT
- How to modify URL structures in custom post types and taxonomies or terms
- Adding meta values to permalink
- Modify custom post type rewrite rules in a separate function
- Permalinks so that one custom post type appears to be a child of another, not working
- Help with a TV series Rewrite structure
- How to achieve this permalink -> category-name/custom-post-type-name/post-name
- Using %postname% tag with a Custom Permastruct creates 400 Bad Request Errors from the server
- Permalink rewrite with custom post type and custom taxonomy
- Prepend meta_value to permalink of post
- How to check if last uri segment is a custom post type or taxonomy term?
- Permalinks using event date (year & month) instead of publication date
- Permalinks for CPT breaks permalinks to pages
- WP Rewrite Rules – Custom post type & taxonomy
- Remove base slug in CPT & CT, use CT in permalink
- WordPress Rewrite rule for nested post types
- Custom Permalink Tag breaks Pagination
- WordPress rewrite my URL when i use pagination
- Custom Permalink for Taxonimie and Custom Post Type
- Add hierarchical taxonomy to permalink for custom post type
- How much control do we have over CPT rewrite slugs? Can I create a “root” page for my CPT with out the page path, and then have paths for other pages?
- Permalink Structure CPT With Custom Taxonomy Fails
- Parent & Child Taxonomy slugs in custom post permalink
- Making a custom help center page
- Custom rewrite rule for hierarchical custom post type
- How to change custom post type permalink structure
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- Customize Custom Post Type URL
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Custom post type permalink returns 404
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Make custom post types and pages place nice, re: rewrite
- Flush Rewrite Rules when new site is created on network
- Pretty URLs and custom post types
- Rewrite rule for Custom post type Monthly and Yearly archive
- Add a permalink variable onto custom post type URL after post name slug
- How to query 2 custom post types that need to share a slug?
- Custom Post Type posts, conflict with posts after add_rewrite_rule to top
- Combine multiple CPT names to create valid permalinks
- Set parent for custom post type archive rewrite url
- Route subpage to Custom Post Type
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- WordPress custom permalink and archive link for custom post type
- Custom Post Type with modified permalink structure results in 404
- Subpages Permalinks Issues
- Rewrite URL for CPT to domain/post-name/post-id
- Category permalinks don’t work even after flushing
- Custom permalink structure for custom post types including multiple taxonomy
- Two CPT: one is using part of the custom rewrite slug from the other
- Template hierarchy changes when custom post-type permalink leverages custom taxonomy
- Associate custom CPT with another CPT’s taxonomy and rewrite permalinks
- Permalinks for a custom post type – with a page template (custom query) and taxonomy archive
- how to use two permalinks for one custom post type based on categories
- WordPress custom post type rewrite rule matches all pages returning 404
- Multiple Custom Post Type permalink issue
- Custom Post Types and rewrite rules – One CPT works and a cloned one doesn’t
- Custom post type child page 404
- Permalink clashing with Custom Post Type rewrite rule
- Parent cpt/child custom post type URL permalink relationship
- How to make nested custom post type slugs work
- Adding rewrite rules to Custom Post-type mixed with Taxonomy
- Custom post type permalink structure
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- How to add custom permalink struct with DYNAMIC author to a Custom Post Type
- Two Permalinks with one Taxonomy (custom taxonomy) and (custom post type -> custom taxonomy)
- What is the best way to relate different custom post types?
- Permalinks: custom post type -> custom taxonomy -> post
- Mixing custom post type and taxonomy rewrite structures?
- How to intercept publish post for a custom post type “event”
- Custom permalinks – post type – hierarchical taxonomy’s
- Custom post types and permalinks : What a mess !
- Custom Taxonomy breaking pages permalinks
- Remove url rewrites for registered taxonomies
- Post Type rewrite rule to point to custom Page/template
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- How to solve this custom post type goes to 404 page?
- How to recover the post ID earlier in the WP admin hook action “firing” sequence?
- Remove cpt slug from url and use custom taxonomy instead breaks all other cpt
- Changing CPT permalink
- How to fix 404 on post after prepending Custom Post Type url with Custom Taxonomy Term slug
- Missing permalink for custom post type
- How to structure a website with custom post types and custom taxonomies?
- The page or ad listing you are trying to reach no longer exists or has expired
- Keep br tags from stripping
- Permalink Trouble with Custom Post Type
- Custom Post Type and Taxonomy pagination permalink
- Paginate yearly archives for a custom post type
- Modify permalink of CPT archive to support two taxonomies