Your rerite rule is incorrect. It should be (assuming download
is name or slug of the page):
add_rewrite_rule('^download/([^/]+)/?$', 'index.php?pagename=download&file=$matches[1]', 'top');
Also, you need to declare the file
query var. A sample and working code:
function createRewriteRules() {
add_rewrite_tag('%file%', '([^&]+)');
add_rewrite_rule('^download/([^/]+)/?$', 'index.php?pagename=download&file=$matches[1]', 'top');
}
add_action('init', 'createRewriteRules');
Note: Don’t forget to flush rewrite rules after adding new rewrite rules.
Related Posts:
- How to trigger 404 for custom query var?
- Custom page template query_vars
- Difficulty with rewrite rules
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- remove query arg from url after set query
- WordPress add_rewrite_rule() cannot visit lower url levels
- Pre-Populate $wp_query settings with custom rewrite rules and custom template_redirect
- query_vars empty when using custom url with custom rewrite rule
- Add URL Rewrite Rule To WordPress
- WordPress rewrite with custom parameter doesn’t work
- Generate custom output on URL with directory
- Own query vars are not displayed
- WordPress Prevent 404 on missing custom post
- Exclude post ID from wp_query
- Can I force WP_Query to return no results?
- paginate_links() adds empty href to first page and previous link
- Get array of posts from the current archive page loop
- Get posts by menu ID
- Last post ordered by publish date using WP_Query on front page
- Meta Query with date and time on the same Day before given time
- In loop: posts have thumbnail AND other variables
- How to grab metabox value in wp_query meta_query key
- Add and in the header while looping over custom query in page template
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- Pagination not working on static page
- How can I create a WP_Query that returns posts where one meta_value
- Get posts from the Main site to sub site – WordPress MultiSites Network
- Query posts with more than 20 comments
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Get array of current post term ID’s
- WP_Query for showing specific post by id
- Implementing an OR statement to wordpress wp_query
- How can i simulate “taxonomy__in” in query?
- Minimize database queries to user tables?
- How to make Meta Query case sensitive?
- Populate tax_query terms parameter with post term
- Orderby the sum of several numeric custom meta fields
- unable to retrive parent page information
- Site not getting correct featured image from my query
- Using WP_Query within an mu-plugin
- wp_query ‘s’, search filter with pagination is not working
- Use more than one query, but prevent duplicates – at scale!
- Modify wp-query and sort by post meta key
- How to display an other custom post type in a different custom post type’s archive?
- Replacing raw database query to WP_Query
- Stale $GLOBALS[‘post’] after custom WP_Query empty result set bothers my template, whose fault is this?
- WP CLI can’t delete plugin related table
- Inserting HTML to close and open divs in WP_Query loops
- Change query from cat id to slug or name?
- Query only the posts with a post format of “audio”
- Display Current Post’s Position in Custom Taxonomy
- Using Wp_Query without the loop?
- WP Query with multiple tags by get the tags
- Custom WP_Query id
- Woocommerce pagination and result count after custom loop
- Easy way to write complex queries in wordpress
- Error with function in functions.php?
- I am having problem sorting custom post type using WP_Query
- WP_Query and is_page_template() conditional
- difference between querying database and using the loop
- How to do logical OR in terms in WP Query?
- Slow Query On Search
- Child pages not affected by orderby
- Write WP Query that selects posts that are part of the same two categories
- Error in meta_query not get result
- Sorting posts by Multiple custom fields in defined order
- Custom wp_query – I’m getting ‘all’ post, not the specific post in the query
- Phpmyadmin – post editing
- wp Query Posts to display in Nivo Slider
- Query not sorting DESC
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Filter products on category AND tag
- meta_query – check for multiple meta values in key which holds an array of values
- How to sort wordpress posts already selected by WP_QUERY
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- WP_Query on custom key and value
- Set “editor” role to existing user
- how to get wp_query posts only first letter of alphabet A?
- How to mix two orderby-parameters into one ordered result
- Custom Post Type WP_Query with filters and search
- Merge wp-query and get_users
- WP_Query how to add a thumbnail to the first post from the last 5 posts?
- Query by meta value (add a dropdown of all values)
- WP Query issue for multiple values
- Calling a function with WP_Query only ever brings the first result
- get last child post by wp_query
- WP_Query don’t working with fixed post_id and term_taxonomy
- How To Query All Attachment Images Found In Post Galleries
- WordPress meta_query not working
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Using orderby with 2 meta keys
- $wp_query when new WP_Query
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Unable to pass variable
- WP Query get posts by specific author IDs if one of several logged in authors
- Edit WordPress loop, taxonomies, & filter
- How to display posts from a specific term first then another posts from another terms using tax_query
- I want to capture the last day’s (today) posts in a category in the numbered order in acf
- How do I have multiple metaqueries inside one wordpress query