You need to write a rewrite URL for the galley, please see the below code and paste into your active theme functions.php file
function gallery_custom_rewrite_rule() {
add_rewrite_tag('%gallery_id%', '([^&]+)');
// Rule to handle numeric slugs in a gallery post type
add_rewrite_rule(
'^gallery/(.+)/([0-9]+)/?$',
'index.php?post_type=gallery&gallery_id=$matches[2]',
'top'
);
}
add_action('init', 'gallery_custom_rewrite_rule', 10, 0);
function gallery_query_vars($query_vars) {
$query_vars[] = 'gallery_id';
return $query_vars;
}
add_filter('query_vars', 'gallery_query_vars');
Related Posts:
- Child post with numeric only slug keeps redirecting to parent
- Can slugs from posts and custom post types conflict?
- Custom Post Type slug has the same Redirection entry
- Remove slug from custom post type post URLs
- How to get custom post type label and singular label from its slug?
- Custom post type yearly/ monthly archive permalinks
- Disable permalink on custom post type
- Using Custom Fields in Custom Post Type URL
- WordPress Custom Post Type is Matching on Partial Slug
- Change slug of registered custom post type in child theme
- Post slug changed using code doesn’t reflect on editor when post is published
- How to achieve this permalink -> category-name/custom-post-type-name/post-name
- Prepend meta_value to permalink of post
- Reslug a Custom Post Type
- Removing CPT slug from URL results in 404 error for archive page
- Getting Post ID from slug during init
- Remove taxonomy slug when not assigning taxonomy with custom post types
- Custom post type’s slug gets wrong when adding a custom meta box
- Custom Post Types Not acknowledged for date.php template
- Bulk 301 redirect for custom post type
- How to redirect all pages of a custom post type [duplicate]
- Redirect to post with only post ID in the URL vs post_type/post ID
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- Custom post type with slug for plural (archive) and for single
- How to redirect wp-admin/index.php to a custom post type?
- Different permalink for CPT and regular Posts/Pages but why?
- How do I fix permalinks for custom post types that has the same slug as a page?
- Delete link on single-custom.php with redirection
- Custom post types archive redirect
- Create/Edit posts and auto-redirect back to listing page
- Why does wordpress keep adding postname to my CPT’s permalink in the end?
- Remove post type slug of all post types from permalinks
- Rewrite slug for CPT
- Is there a way to have custom post type and page with the same slug?
- Using Same Slug With Multiple Post Types
- Rewrite post type slug only for child theme
- redirecting improperly after updating custom taxonomy term when referring from CPT edit page
- Adding Post id to the end of slug in a Custom Post Type
- Remove the parent slug in a CPT URL
- Permalink for a custom post type isn’t working and I don’t know why
- Index page with the same id as the slug
- Redirect 404 page with ID in slug to associated page with same ID in slug
- How can I make the slug of the taxonomy also the slug of the custom post
- Assign same parrent Page to pages AND custom post types
- Multiple (two) category postings on the same page.
- Removed custom post type slug but not working for child pages
- Custom Post Type – Duplicate Page Slugs
- Some posts from custom post type to subdomains
- Remove permalink for custom post type
- Custom Post Type archive-{post-type}.php not working
- Custom post type single page (single-{CPT-name}) 404 when slug includes hyphens
- Slug for custom post type
- Rename a slug label
- Custom URL redirect in WP
- Redirect to archive is single post has a certain term assigned to it?
- Using page slug in wp_query
- Redirect to first child on Custom Post Type (without template)
- Listing all slugs?
- WordPress Custom Post Type – Rewrite Query
- Check if user has custom post published redirection on WordPress
- Automatically update slug with latest title within custom post type [duplicate]
- Custom Post Type archive redirects to home
- How to use a specific custom field in a custom post type as slug
- sort by name (slug) custom post type
- How to change CPT single post slug
- Custom taxonomy permalink without term, redirection to CPT slug
- Custom Post type dont use custom page template (slug is not right)
- How best to structure multiple CPTs and tax within a ‘resources’ section
- Difference between a default post type and a custom post type?
- How can I write slugs / permalinks as: custom post type -> custom taxonomy and custom post type -> custom taxonomy (one CPT and many taxo)?
- Custom Post Type not using correct page template
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- Custom Function to redirect singular post if specific meta field is empty
- Change permalink incrementor into pseudo-subdirectory
- How to redirect custom post type posts to one url with htaccess?
- Custom post type URL structure with site.com/custom_taxonomy_slug/post_name
- Custom Post Type duplicating slug for new posts
- WP gives 404 error for custom post type with GET variable
- Custom taxonomy archive slug overwrites static page
- Slugs on hierarchical taxonomies
- Getting a 404 on single custom post type page when using rewrite on a custom taxonomy
- How to develop custom URL redirection
- Generate slug and meta data if meta field is empty
- Get full control over custom post type url
- Redirect Custom Post Type after user submits update
- Add category slug as class attribute in a link array
- Relationship with 2 custom post types
- Costum post type with costum (sub)taxonomy
- Remove Custom Taxonomy Slug only without removing Custom post type slug in permalinks
- Category slug not showing for Custom Post Type
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- WordPress pagination URL
- is this a bug or not?
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- Hide custom post type slug url from search engine [closed]
- Is it possible to use a post name in a custom post slug?
- Custom slugs with dates & IDs on Custom Post Type
- How to change permalink structure off default posts and also CPT’s posts
- Add post id to url instead of WordPress default -2 suffix
- Taxonomy Archive URL + Template