It’s a bit simpler to let WordPress handle generating the permastruct when you register your post type. I also recommend against using global variables, there are API functions for most of what you need to accomplish with the rewrite class.
function magazine_issues_rewrite() {
add_rewrite_tag( '%issuenumber%', '([^&]+)' );
add_rewrite_tag( '%issueyear%', '([^&]+)' );
// post type registration, other args removed for clarity
$args = array(
'rewrite' => array( 'slug' => 'issue/%issueyear%/%issuenumber%' ),
);
register_post_type( 'issue', $args );
}
add_action( 'init', 'magazine_issues_rewrite' );
I’m not sure whether or not that will fix your problem, I haven’t tested your full code.
Related Posts:
- Permalinks using event date (year & month) instead of publication date
- Query all posts where a meta key does not exist
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- what is the correct way to compare dates in a WP query_posts meta_query
- Advanced search form with filters for custom taxonomies and custom fields
- Can a custom post type have a Parent Page?
- Where, When, & How to Properly Flush Rewrite Rules Within the Scope of a Plugin?
- Meta query with boolean true/false value
- Get post with multiple meta keys and value
- Correctly delete posts with meta and attachments [duplicate]
- 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
- CPT Template Not Showing – Getting 404
- Custom post type 404s with rewriting even after resetting permalinks
- Multiple post types – share same ReWrite slug?
- Storing revisions of metadata for custom post type
- Custom field values deleted when trashing custom post type
- How to get all custom fields of any post type
- Update CPT meta data using REST API
- Rewrite rule for Custom post type Monthly and Yearly archive
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- add_rewrite_endpoint() not working for custom post type archives
- Echo all meta keys of a custom-post TYPE
- Custom Post type – how to get checkbox to update meta field to null
- How can I filter posts by post_parent in the admin?
- Permalink rewrite 404 conflict- WordPress Taxonomies/ CPT
- How do I Paginate Search Results for Custom Post Types?
- Ordering posts having multiple post-meta date fields
- How to modify URL structures in custom post types and taxonomies or terms
- Adding meta values to permalink
- Custom Post Type with Input fields to seperate table on database.
- Archive page with multiple taxonomies rewrite
- How do I remove all the metaboxes for a custom post type?
- Modify custom post type rewrite rules in a separate function
- Custom Queries: Joining On Meta Values From Two Custom Post Types
- Gutenberg how to make attribute to save to meta
- Permalinks so that one custom post type appears to be a child of another, not working
- Help with a TV series Rewrite structure
- Taxonomy archives based on Custom Post Type
- How to programmatically create a connection with [Plugin: Posts 2 Posts] on cpt publish?
- Post metadata deletes itself
- How to create a mini directory in WordPress?
- How Can I save multiple records in same meta key?
- How to achieve this permalink -> category-name/custom-post-type-name/post-name
- Change page /2 to /transcript with a Rewrite
- Using %postname% tag with a Custom Permastruct creates 400 Bad Request Errors from the server
- Get all posts from custom post type and insert in select input as metabox
- WordPress Custom Post Type Category Page
- Permalink rewrite with custom post type and custom taxonomy
- Detect meta value changes when post is updated (post_updated)
- Search everything (posts, pages, tags, cpt, meta)
- How to Add Pages Under Custom Post Type URL Structure?
- Prepend meta_value to permalink of post
- How to check if last uri segment is a custom post type or taxonomy term?
- Pagination Doesn’t Work
- Rewrite custom post type url’s adding meta box values
- Custom Post Type: Set post_title equal to a custom post type field
- I can’t set meta_key in my custom post type query
- Grossly inefficient wordpress loops!
- Compare 3 custom fields and sort by oldest
- Multiple parameters in a custom post type url rewrite
- Permalinks for CPT breaks permalinks to pages
- Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url
- WP Rewrite Rules – Custom post type & taxonomy
- How Do I Use WP_Query to Run This Database Query as Search Result?
- Custom Post Types: pretty search URLs and has_archive
- Need help with complex custom post type setup
- WordPress Admin Panel search posts with custom post meta values along with title
- Custom Post Type pagination when CPT ‘rewrite’ rule and a page have the same slug
- WordPress monthly archive links result in 404
- Creating a custom post type upon registration
- How to Update post status using meta data in Custom post TYpe
- Remove base slug in CPT & CT, use CT in permalink
- Rest Api v2 orderby meta_key in custom post type
- bulk Update post_meta with default values
- Rewrite rules for custom post type ‘attached’ to another custom post type
- Reason action hook won’t work with update_post_meta from frontend form? Alternative?
- Can’t sort order of wp_query with 2 meta keys
- Showing Meta Data for Custom Post Types?
- How to get source of custom meta image?
- wrong template for page of archive
- Having trouble with custom post type / meta box
- Query for posts from any post type but only add instock products
- How can I include meta box content when searching?
- update a post meta from a single table cell TablePress
- update custom post type meta from a shortcode
- Custom Meta Boxes – Nonce Issue – Move to trash issue
- WordPress Rewrite rule for nested post types
- Displaying Meta Box Image
- Custom Post Type rewrite redirects to homepage
- Custom post type category not displaying in custom post type
- How to make custom post meta wp_editor translatable?
- Automatically adding meta data to posts or multiple query help
- How to keep a check box in custom meta box for custom post type checked by default for add new post?
- How to add multiple featured image in meta box in post editor?
- Show metabox in custom-post-template depending on taxonomy term?
- Disabling post_type in URL
- single-{post_type}.php is not loaded despite flushing rules