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
- Custom Post Type – Duplicate Page Slugs
- Some posts from custom post type to subdomains
- Remove permalink for custom post type
- Auto Slug Generation for Custom Post type
- How to make a posttype show under a page hierarchy (example.com/page/posttype/entry)?
- Custom Post Type archive-{post-type}.php not working
- Custom post type single page (single-{CPT-name}) 404 when slug includes hyphens
- How do you create %post_type%/%postname%/ permalink structure?
- Changed permalink structure of CPT – should I redirect?
- Slug for custom post type
- Rename a slug label
- Custom URL redirect in WP
- Slug Confusion Between Post and Custom Post types?
- How to find a specific post_type using its “rewrite slug”?
- Different slug taxonomy for two different CPT
- How to add current custom taxonomy slug to body class
- Change Slug of a Custom Post Type
- Redirect to archive is single post has a certain term assigned to it?
- Using page slug in wp_query
- How can Custom Post Type and a page have the same slug?
- Redirect to first child on Custom Post Type (without template)
- How to get postname in custom page?
- Listing all slugs?
- Why WordPress is picking archive.php instead of page.php?
- Changing slug of all posts
- WordPress Custom Post Type – Rewrite Query
- WordPress different templates for same type custom post (but different slug)
- Create short URL with auto 301 redirect
- Check if user has custom post published redirection on WordPress
- Custom Post Type Advanced Slug
- Automatically update slug with latest title within custom post type [duplicate]
- Custom Post Type archive redirects to home
- Apply template by path/slug related to custom post type?
- Changing CPT slug and taxonomy already registered in parent theme
- Custom Post Type to replace Woocommerce products – page not found error
- Custom Post Type for Shortcode Use – Prevent it display as a post (with slug)
- rewriterule not working
- How to use a specific custom field in a custom post type as slug
- Custom Post Types and Removing Slugs – should we do it?
- sort by name (slug) custom post type
- Need to return a string as permalink insted of str_replace
- How to controll the Posts post type and general wondering about WP data structure
- Under What Conditions Can I name my CPT the same as my CPT Page?
- How to change CPT single post slug
- Custom taxonomy permalink without term, redirection to CPT slug
- redirect after submiting post for review
- How do I set a post slug automatically based on taxonomy?
- Custom post type and multi taxonomies + customize url
- Custom Post type dont use custom page template (slug is not right)
- How best to structure multiple CPTs and tax within a ‘resources’ section
- Custom rewrite rule based on other custom post type title
- Redirect Existing Post to CPT
- Use custom post type taxonomy between cpt slug and name
- Faking “Same Slug Root, Multiple Custom Post Types” with Redirects?
- Issues with static pages redirecting towards home.php
- Show code dependant on CPT & category
- Difference between a default post type and a custom post type?
- Remove custom taxonamy slug with pagination
- How can I write slugs / permalinks as: custom post type -> custom taxonomy and custom post type -> custom taxonomy (one CPT and many taxo)?
- Post Click Redirect to Custom URL instead of Single Post Page
- Custom Post Type not using correct page template
- WordPress doesn’t respect Page slug in custom post type url pagination. Keeps getting removed
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- Output all terms slugs for a loop filter
- Custom Function to redirect singular post if specific meta field is empty
- Custom Post Type canonical link / pagination redirecting to root
- Change permalink incrementor into pseudo-subdirectory
- add .html to custom post type with WPML
- 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
- How to override post-new.php with custom template
- Custom post type post_type_link gives “page not found” on any other custom post type
- Custom 404 redirect for a luddite
- Two CPT: one is using part of the custom rewrite slug from the other
- WordPress page not showing up – replaced with last 10 posts?
- Redirect users in first login to a dynamic link
- Custom permalink rewrite rules – how do I fix this?
- WP gives 404 error for custom post type with GET variable
- Custom taxonomy archive slug overwrites static page
- Slugs on hierarchical taxonomies
- Display a Custom Post Type within another with hierarchically slug
- Redirect sub-page URLs to parent without changing URL
- Problem to get the link of the default ‘post’ post type like the orther custom types
- Getting a 404 on single custom post type page when using rewrite on a custom taxonomy
- Can I override the permalink/slug on creation
- How to develop custom URL redirection
- Get the custom post type slug but remove the rewrite prefix?
- Rewriting archive page slug to be different than custom post type slug
- Generate slug and meta data if meta field is empty
- Get full control over custom post type url
- custom post type archive slug vs. custom page template
- Redirect Custom Post Type after user submits update
- Redirection error after posting a comment on a custom type post
- Add category slug as class attribute in a link array
- Relationship with 2 custom post types