add_rewrite_rule()
cannot automatically create that permalink structure for you. You should use wp_link_pages_link filter. E.g:
add_filter('wp_link_pages_link', function($link, $i)
{
global $post, $photo_id;
if ($photo_id && 'gallery' === $post->post_type)
$link = $link . "https://wordpress.stackexchange.com/" . intval($photo_id) . "https://wordpress.stackexchange.com/";
return $link;
}, PHP_INT_MAX, 2);
Then, you must use add_rewrite_tag() to make WordPress aware of photo
query string:
add_action('init', function()
{
add_rewrite_tag('%photo%', '([0-9]+)');
add_rewrite_rule('^gallery/([^/]+)/([0-9]+)/([0-9]+)/?$', 'index.php?post_type=gallery&name=$matches[1]&page=$matches[2]&photo=$matches[3]', 'top');
}, 0, 0);
Related Posts:
- When should add_rewrite_tag() be used?
- Why does everybody hook add_rewrite_rule on init
- add_rewrite_rule() vs $wp_rewrite->rules vs ‘rewrite_rules_array’?
- How to check if a rewrite rule exists
- add_rewrite_rule not producing anything in $_GET
- Flush_rewrite_rules not working when settings updated
- Case-insensitive add_rewrite_rules in WordPress functions
- Clean URLs for custom $_GET variables
- Prettified page URL w/ query var redirects to prettified page URL w/o query var
- flush_rewrite_rules() cancels the effect of add_rewrite_rule()
- Separate posts by chapter per rewrite
- Redirect taxonomy to custom template to list terms in taxonomy
- How to change the matches in add_rewrite_rule
- Using add_rewrite_rule() to redirect to Front Page
- add_rewrite_rule() not working
- Rewrite rules and query for virtual page
- add_rewrite_rule parameter is not received by the page
- add_rewrite_rules prefix everything
- Can someone explain the function of the third parameter of “add_rewrite_tag”
- get_query_var with add_rewrite_rule and add_filter(‘query_vars’) not working
- Can rewrites fallback if 404? Rewrite conflict issue
- Reading Settings -> Front Page displays “Static Page” being reset
- add_rewrite_rule query_var not being set
- why does add_rewrite_rule refresh and loose url variables
- Where do I USE add_rewrite_rule?
- add_rewrite_rule confusion
- Custom Rewrite rule to match anything not already matched by WordPress
- Uppercase to Lowercase in URL
- How to use rewrite rule or rewrite endpoint to switch languages?
- Remove rewrite endpoint on deactivation?
- Do I need to flush rewrite rules when creating new user if using custom author rewrite rules?
- Simple page URL rewrite with add_rewrite_rule()
- Hooking “delete_option_rewrite_rules” for rewrite rule addition
- Custom URL rewrites work, but break my permalinks
- WordPress shows front page, when it should show 404 with pagination style urls
- Rewrite rule problem
- add_rewrite_rule redirects if value = 1
- Pass query vars to front page
- add_rewrite_rule permalinks break in WordPress 4.5
- How to add rewrite rule for external php file
- Rewrite rule for path of favicon.ico ( Add_rewrite_rule function possible ? )
- FLUSH_REWRITE_RULES – after or before REGISTER_POST_TYPE?
- Using get_query_var() from a plugin
- How to flush rewrite rules on the activation of any plugin
- Rewrite without query parameter
- WordPress CPT slug and page slug conflicts
- Mod_rewritte – remove ?m=1 from url
- Rewrite Rules problem when rule includes homepage slug
- WooCommerce – Conditional for page created by rewrite_rule
- flush_rewrite_rules() not working on updating Settings API
- Rewrite rules priority
- Rewrite rules for short URL
- How do I turn off the blog and archives?
- Add_rewrite_rule doesn’t seem to work?
- Grab last part of the url inside rule
- Leverage WP_Rewrite to pre-validate links / detect invalid links
- How to do make mysite.com/post-name/sub-post?
- Custom rewrite rules for a page with GET variables?
- When request has multiple matching rewrite rules, and matched rule returns 404 – iterate to next rewrite rule
- WordPress add a rewrite rule to a page to accept a GET variable
- “/” URLs without trailing slash shows 404
- How can I resolve search error with pagination wordpress
- CPT – Nice url with add_rewrite_rule
- get_author_posts_url() doesn’t return the author URL, because of wrong author_structure
- add_rewrite_rule only works when flush first
- Homepage rewrite rule
- WordPress add_rewrite_rule with 2 variables
- Rewrite rule not working, issue may be in URI request
- custom rewrite rules will not be added to wordpress rewrite_rules database
- rewrite rules problem with #comments-2345
- Overcoming a complex WordPress page rewrite rules request
- How to create a custom URL to another domain in WordPress
- Why isn’t my rewrite rule for add_rewrite_rule not working as expected?
- Custom Fields Query Vars and Rewrite not working
- Rewrite Rules, Query Vars and Pagination
- Pretty links with add_rewrite_rule and add_query_var
- How to change URL in WordPress
- WordPress Rewrite rule with custom query var
- default ‘post’ post type: not forcing url rewrite when args set
- How to add rewrite rule to point to file
- Last query_var not working with rewritten URL
- Rewire Rules Front Page
- How to use endpoint, but remove/rewrite endpoint base?
- WordPress URL rewrite after changing web from Joomla
- add_rewrite_rule doesn’t work for me
- Rewritten URL not loading WordPress environment
- WordPress Custom post type single page 404 error
- Rewriting base name Taxonomy same Post Type
- Where to hook to bypass instantiating WP_Query?
- Rewrite for page with a possible unknown parent page
- Rewrite the WordPress URL from custom plugin
- add_rewrite_rule works only with one “directory”
- How to Add Rewrite Ruled Argument Into Permalink Properly
- Overwrite WP’s default search rule to redirect to my own template
- Custom URL rewrite with add_rewrite_rule
- Rewrite rule to index.php in theme subfolder
- Direct domain alias to a specific WordPress page without the page in the URL
- rewriteRules WP6
- WordPress rewrite rule – not able to access second and third parameters
- Custom URL Rewrite Rules not working