Here is my current code:
function hm_base_date_query_vars($vars) {
$vars[] = 'base_date';
return $vars;
}
add_filter('query_vars', 'hm_base_date_query_vars');
function hm_base_date_rewrite_rule() {
add_rewrite_rule(
'^my-calendar/([^/]*)/?',
'index.php?pagename=my-calendar&base_date=$matches[1]',
'top'
);
}
add_action('init', 'hm_base_date_rewrite_rule', 10, 0);
$base_date_test = get_query_var('base_date');
on the url example.com/my-calendar/foo
my var $base_date_test
returns null
Maybe someone can help me. Thanks.
// Edit: It works. I tried to call the var in functions.php but I had to call it in my custom php template -.-
Related Posts:
- How to Modify Existing Rewrite Rules?
- Add additional URL variations for a Post
- Need help with add_rewrite_rule
- remove “index.php” from permalinks
- Custom post type permalink endpoint
- How to add a custom URL placeholder to author archives?
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Make post slug have priority over category slug
- Custom Rewrite with Query vars
- Using two permalinks for one post
- flexible rewrite ‘ramble’ URLs with WordPress
- Change the custom post type permalink
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- Rewrite url / permalink for default archive – yearly / monthly
- Permalinks, Rewrites, Get Variables, Oh My!
- Change permalink for a single post entry
- Rewrite URL Parameter And Force ‘Pretty’ Permalink
- rewrite_rule for custom post type doesn’t affect get_permalink
- Add ‘articles’ prefix before blog posts url without affecting pagination
- custom permalink/shortlink with base62 encoded post ID
- When is it a good idea to build a permalink structure from scratch?
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- Call to a member function add_rule() on a non-object
- I need a custom permalink for my website
- Permalinks: Page Not Found
- Why is add_rewrite_endpoint incompatible with /%category%/%postname%/ permalink structure?
- Re-write specific custom post type category URL to go to another page
- how to add rewrite rule to wordpress default post type
- Remove custom taxonomy base from URL
- Custom query var rewriting with only variable
- remove sub-category of Custom Post Type from permalink structure
- add_rewrite_rule not working for me
- Is a permastruct possible on pages?
- Using WP Rewrite, but just not “getting it”
- Rewrite rule for a query string
- Share same Slug for a Custom Post Type and 2 Taxonomies
- How to remove specific category from URL in WordPress
- Rewrite CPT permalinks and include WPML language
- Redirect Uploads Folder to Query Vars in WordPress
- Custom permalink leads to index page
- Rewrite rule intended for CPTs gives 404 for pages
- Permalink structure between 2 custom post types and a taxonomy
- Permalinks only for posts
- Custom rewrite rule ignored
- wordpress how to replace url /bar with foo/bar for custom post type
- Getting back a permalink from custom url
- Order custom post type posts by custom field with pretty URL
- Adding URL prefix for foreign language support
- Exclude single page from permalink rule
- help to remove last trailing slash using add_rewrite_rule
- add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
- How can I set up a secondary permalink structure?
- Rewrite rule not passing variable
- How to Use metada Value in Url and is it possible? [duplicate]
- Safest way to create a custom permalink
- Creating an alternate path for a page
- corrupted URLs – can’t leave starting page
- rewrite based slug standar post wp
- Create different permalinks for same post
- remove SLASH on single_post but KEEP on categories and parent pages
- Multiple Taxonomy Items for Separate URLs
- WordPress keeps removing query var from the URL
- Multiple URL rewrite rules and get every prams
- Using a template file for a specific custom URL
- WordPress Multisite ABSPATH and get_home_path() to check for htaccess or web.config file
- Redirect page to homepage, keeping URL
- Add slug to default post permalinks ONLY
- Custom permalink question
- how to have same rewrite rules for 2 different post type?
- Permalink structure /page/page/cpt-post gives 404 with pagination
- What permastrusture tags are generated out of the box right after creating custom post types and taxonomies?
- No Ones Been Able to Override my WordPress Rewrite Rule Issue!
- Rewrite posts url as they’re all children of a page
- a way to support totally different url structure
- Multiple Permalink Patterns for one page
- WordPress Pagination Custom Rewrite Rule for Pages
- rewrites and custom links in page need help with add_rewrite_rule
- Prevent guessing slug
- WordPress permalink still not working (error or not understood?)
- WordPress custom permalinks, pages are now 404
- How to add query parameters to all internal links?
- Nice RSS Feed URLs for each custom post type
- Can’t get rewrite rules working
- How to add a variable as a tag base?
- Custom permalinks with hierarchical taxonomy – getting PHP warning
- How can I emulate permalink behaviour on static pages
- Remove some rewrite rules in wordpress
- WordPress pages and posts are redirecting to server IP address instead of domain URL [closed]
- “set_front” => false on custom post type breaks wp_list_categories links [closed]
- Passing parameter through permalink structure
- Add word to permalinks does not transform the urls
- How to change URL of my pages?
- Converting WP Page to use full explicit paths?
- Add Custom Pagination Permalink
- Customize category permalinks
- Losing the original URL when using add_rewrite_rule
- URL to an image in a post is changing when permalink is set to custom. Can I avoid this?
- permalinks url with woocommerce
- Blog url disappears
- How to make my custom permalink pull up the correct post