Maybe you are not using the correct hooks nor the correct rewrite rule. You are rewriting to pagename
, which is for pages. You should use name
to get posts by slug.
add_filter('query_vars', 'cyb_add_query_vars');
function cyb_add_query_vars( $vars) {
$vars[] = "item";
return $vars;
}
add_action('init','cyb_add_rewrite_rules');
function cyb_add_rewrite_rules() {
add_rewrite_rule( ''^shows/([^/]+)/([^/]+)/?$'' , 'index.php?post_type=shows&name=$matches[1]&item=$matches[2]' , 'top' );
}
You can also add a endpoint and use URLs like http://my-website.com/wordpress/shows/show-slug/item/episodes
:
add_action('init','cyb_add_endpoint');
function cyb_add_endpoint() {
add_rewrite_endpoint( 'item', EP_PERMALINK );
}
And don’t forget to flush the rewirte rules. If you don’t want to code the flush, visit the permalink settings page in wp-admin area, click on save and the rewrite rules will be flushed.
Related Posts:
- Add .html (dot HTML) extension to custom post types
- Custom post type yearly/ monthly archive permalinks
- 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
- How to have a custom URL structure for a custom post type?
- WordPress custom post type url change
- remove post-name from title in custom post type
- Custom query variable – get wordpress to redirect to nice permalink url
- Rewrite Custom Post Type URL slug
- How do I get the permalink structure to work like this?
- CPT Archive with core Category
- Custom Post type and permalink settings
- Custom Post Types, URL rewrite on multiple CPTs
- Get Taxonomy Term Title by it’s URL
- Front custom edit post page for each post
- How to build custom route by adding taxonomies to URL ? ex: www.demo.com/communities/palo-alto/
- Rewrite Question Mark in Post Template to Make it Pretty URL
- Ignoring slug capitalization on rewrite rule for custom post type archive page
- Taxonomy in URL
- Custom post type archive with page as parent url
- Custom Post Type Category URL
- How to create custom search result page with custom URL parameters for custom post type?
- Custom post type URL
- Archive page for custom post type and custom taxonomy
- Custom Post Type URL Rewrite’s
- Custom Post Type Date Based Archive URL rewrite [duplicate]
- returning the currect URL for nested posts
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- How to change URL for custom post type archive?
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Set archive of custom post type like ‘posts’ page in reading settings is set
- How to manage a custom post type archive as a page?
- How to manage a custom post type archive as a page?
- Show index and not the archive for “Dog Custom Post” with default slug
- Force WordPress to only match URL in category
- Custom post type with parent page? Possible?
- Stop Custom post type from being searched via URL
- Why is a custom post type’s URL “/?cposts=name-of-the-post” but default post’s URL is “/?p=ID”?
- Customize category URL
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- Custom archive URL as a subfolder of the custom post type slug
- Custom post type with custom taxonomies structure url not working archive of CPT
- Rewrite rule taxonomy url with different values in one function
- 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
- 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)
- 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
- Custom taxonomy and post type with same slug
- Best structure / rewrite rules to achieve the following url
- Custom permalink with child taxonomy terms
- Paginate_links in custom post type template
- My archive-posttype.php template is not loading
- CPT category hierarchy
- 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
- Create Custom Post Type as page
- Best way to specify “article type” in URL
- 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 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
- retrieve permalinks of posts inside custom post type by using post ID
- Custom URLs in post types make it impossible to view archive
- How can I use archive-{post_type}.php theme template?
- How to display CPT archives?
- Custom meta Title for custom post type archive from page
- 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?
- current-menu-item not added on page showing custom post type (rendered with archive template)
- Alphabetically sort a taxonomy.php template by post title
- How does: /index.php?post_type=event&event-date=2011-07-25 work? What if it doesn’t work?
- Custom Permalinks for Custom Post Types
- post_type_link Filter – Too Few Arguments
- Postname on unique permalink structure appends “-2” for a custom post type. How can I get this to stop happening?
- Share root slug for Child Page and Custom Post Type (prioritizing child pages over posts)