You need to flush rewrite rules on plugin activation for your custom post type to begin working.
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
register_activation_hook( __FILE__, 'myplugin_flush_rewrites' );
function myplugin_flush_rewrites() {
// call your CPT registration function here
// (it should also be hooked into 'init')
dwwp_register_post_type();
flush_rewrite_rules();
}
You may have noticed it randomly working without having to do this, if some other code flushed rules, such as when you visit the Settings > Permalinks admin page.
Related Posts:
- Custom permalink structure only for default posts
- Custom post type single (permalink) throws a 404 error
- Custom post type permalinks breaking due to 3.1 bug fix
- Move first half of posts to one parent page, second half to the other page
- How could I change my Permalink from blog to custom structure? [closed]
- register_post_type permalink
- Post titles and thumbnails as links to custom post types?
- Changing permalink of WordPress
- Permalink base only for posts
- Append a random string to a post permalink
- Default post type doesn’t display in url
- Changes done in admin panel are taking time to reflect in the REST api responses
- Any way for get_next_post() to use the actual post order instead of publish order?
- Calling Different Custom Post Timestamps in a table
- how do i add posts-page slug before posts slug in permalinks
- WordPress Multisite – Create Default Post and New Category On New Site Install
- Admin – create custom post status and display above table
- custom post template file not shown, instead all the time 404.php
- Set Default Category to Username
- How to allow visitors to filter posts by multiple taxonomies
- show custom post type category dropdown sorting result on same page
- Custom Post Type Rewrite To Include Parent Page(s)
- Permalink doesn’t get displayed in Twitter button (Local WordPress problem?)
- Retrieve post ID from “querying” URL
- Thumbnail & Category link aside post
- hiding permalink in admin if the user is subscriber
- Why does WP_Post not contain its permalink?
- the_permalink() not working in a root installation
- When changing pages to posts, how do you set up 301 redirects for the page URLs?
- How to include my own css in post
- Custom post types related to same custom post type?
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- Dynamically switch template on click
- “about us”, ” contact” sections should be article(post) or page in the simple small Business website?
- Is it possible to customize the post according to post format in single.php?
- Customize rel=canonical tag for single blog post
- a little direction on custom post type
- disable Tab post on nav-menus page (Admin)
- Second get_permalink inside loop points to wrong URL
- Format latest/newest post differently
- Custom taxonomy archive page problem
- Tell WP to use a specific template file in posts
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- relating business and products with custom taxonomy?
- Best Way to Add UnEditable HTML to Posts
- How safe is it to delete old posts edits to save database space?
- Two Custom Post Types with Identical Articles Competing for the same Slug
- Custom Post Type archive
- WordPress custom post type with folder structure in slug
- Using setup_postdata() with multi-dimensional array
- Is codex right on deleting post?
- Custom Permalink Structure for Pages & Posts
- Check if a custom post type has already been created
- WordPress Query Posts From Category Post on Static Page
- Edit multiple custom post types while saving a new or edited post
- Create a custom posts page
- How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?
- if in category but only with post meta
- How to get different Related Posts
- custom word in custom permalink structure
- How to add convenient buttons for new custom post statuses
- How to allow multiple thumbnail upload for Posts?
- add external project to web site wordpress on production
- Deleted a user with administrator rights. Now all the data/content/images are lost. how to recover them back
- Show custom post with custom categories with specific slug
- Display the 2nd category name of a custom post type without error if its null?
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- Post is blank when I click on the link
- Auto delete posts based on content text
- How to call posts under a specific category on static front page?
- Querying another post category to match current post and display in loop
- Custom home page with full post for first one only
- Custom Post Limit for homepage only without plugin?
- Custom permalink for each post
- Display value of custom field at the beginning of a post
- Unabled to Change Permalinks – Even Using the “Edit” (Resets to Original Permalink on “Update”)
- l accidentally permanently deleted a Draft. There’s any way I can recover it?
- datepicker value in mysql
- Inserting an example of the last 3 post on to the homepage
- Post/page title to permalink transformation – what is behind the scenes?
- Static pages not working
- When WP_Query only returns 1 post, how do I automatically redirect to that post?
- Optimize CPT-function with a loop
- Add post tags to previously created custom post type
- Can WordPress handle following functionalities?
- Simple Custom Metabox Not Saving
- Get a term each custom post type
- Change default post style to columns
- Custom Post Type, post-formats associated to custom post type > 404 archives
- Internal linking to posts permalink fail because of spaces and stripe at postname
- How to display only one category in a custom post type?
- Adding a custom post type meta field to rss
- How to restore deleted post related with deleted users
- Link post images to post
- Help with listing current users submitted custom post type in template file
- Making posts permalinks consistent numbers
- Delete post from admin but not from database
- Custom Post Type Single Loop Outputting Wrong Post
- add_rewrite_rule and template redirect not working
- Can Permalink structure of %postname%/%post_id% improve performance