Your code worked absolutely fine for me, so I suspected you forgot to flush the rewrite rules.
Each time after you added code which alters the WordPress rewrite rules, e.g. add_rewrite_rule()
or code which registers/un-registers a CPT or custom taxonomy with URL rewriting enabled, you should always flush the rewrite rules which means WordPress will empty/reset the saved rewrite rules (in the database and .htaccess
file) and regenerate (and re-save) them which would include your newly added or updated rewrite rules.
How to flush the rewrite rules: Just visit the Settings → Permalink Settings page. And there’s no need to click on the “Save Changes” button.
There’s also a programmatic way (see flush_rewrite_rules()
), but in general, the above trick is the preferred way unless you are writing a plugin where you would for example, call the function during the plugin activation and deactivation.
Related Posts:
- How do I find out the full path of a page’s template?
- How to add download link from database on custom page template?
- What is the difference between an ORM and an ODM?
- Rename a table in MySQL
- How should I tackle –secure-file-priv in MySQL?
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Keeping WP database synced across multiple developers using git
- Staging sites, how do you manage synchronising updates in the DB?
- How to get the post publish date outside the loop?
- How to define composite keys with dbDelta()
- Is it possible to define two databases for one installation?
- Forcing nickname as display_name in custom edit profile template
- Connect forms in WP to external database
- Hook into $wpdb
- How to get site URL if database is disconnected?
- Is it wise to delete post revisions and autosaves from database?
- Multiple WP install with same users database
- Dynamic data in `wp_register_script` needed
- Using two different DB users on one WP install
- Usage of Direct Database Call Without Caching Error
- Can I transfer a mysql database to another site?
- How to verify password outside WordPress?
- Weird issue with database migration and SSL links
- Merge two databases: OLD SITE -> NEW SITE
- Backup another database with BackUpWordPress plugin [closed]
- Easiest Way to Authenticate WP Users Using an External DB?
- How to use a different database to list and manage comments in the backend
- How to check if a core update, like 4.9.8 → 5.0, involves a database update (migration)?
- Error establishing a database connection on Installation
- Why is it that not all users have a ‘session_tokens’ meta_key record in the usermeta table?
- I need to get an array from the wordpress database
- Moving minor updates between local and live sites – just database?
- Use mulitple usernames?
- Routine to convert custom post meta from old to new value
- “The link you followed has expired” & “Error while saving” messages when adding new post
- input data and output table [closed]
- database connection [closed]
- sanitize POST arrays
- WP character encoding error after sharing post on Facebook �
- Sending data with multi step form to wp database
- Able to use all admin pages but in the frontend there is a “Error establishing a database connection”-Error
- WordPress query is not returning proper results
- Localhost to Staging to Development Dynamic WP-CONFIG
- Selectively restoring original posts from a compromised site to a freshly installed WordPress database
- can we add extra table or column in wordpress for adding our data
- $wpdb is not initiating
- Duplicated site isn’t recognized as a site
- My options table is huge. What can I do?
- Changing root password in PHPMyAdmin for WordPress Database when going live
- How to properly check if a table exists in WordPress Database using Show Tables Query
- How to delete database without using any plugin?
- multiple wordpress installation with shared usertable on an different database
- wordpress database restore – broken link
- 6 random character prefix automatically added to entire DB tables, how / why? [closed]
- Insert Custom Data into wpusers
- Fill custom select field with pages/post titles
- Delete/Replace words from X to Y in post content
- How to delete a particular row in a database table
- Location of image metadata on my server
- How to create more than one new wpdb object?
- Multiple WordPress sites installs sharing the same database but with different content and domains
- Remote database -> massive response time increase?
- Is it good practice to import/export a blog to test a redesign?
- Getting value from database table depending on field value
- Getting “Error Establishing a Database Connection” on localhost in new Mac OSX Lion environment
- Secure way to use name_save_pre?
- wpdb->insert not inserting first variable
- Database tables for sports betting integrated in WordPress
- change the year on all of my custom post types?
- custom tables in wordpress Database? (can i just create them with sql?)
- New installation fatal error in 5.9.3 at edit or create entry
- Storing transients giving database error
- I want to replicate a wordpress website over multiple servers
- Accidently changed the GUID
- Is there anyway to split posts to different databases?
- wp-cli + valet: “Error establishing a database connection”
- local wordpress broke after changing URL
- Unable to login to a https website via the app after changing from http
- mysqli_query(): MySQL server has gone away for Curl Request
- Is it safe to add INDEX to a column in WordPress database?
- Restore Old Database Over Newer WP & Plugin Files
- WP website showing blank page after moving from subdomain to main domain
- create a table using user meta custom data
- Database structure for thousands of posts
- WPCLI search and replace in a particlar site dir effect another site-dir
- How do I find out from my database what version of WordPress I need?
- How to create a database table?
- Accessing content from third party as native posts in WordPress
- Extracted CSV as Array for Custom Query Loop
- Hang Up Followed By Can’t select database
- Database error after importing WordPress
- One WP Database outside localhost and two connections
- Fetch data from another site, but the same database
- Pulling values from a sepcific row in table
- Every time I update or install a plugin I get “Error Establishing a Database Connection in WordPress”
- import (migration) user database to wp-users
- Create hundreds of users with just ID in phpMyAdmin
- What is best for saving lot of extra detail of user?
- Insert Extra fields added in the front end registration form to DB
- Cant Connect to Database