{"action":"created","issue":{"url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/313","labels_url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/313/labels{/name}","comments_url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/313/comments","events_url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/313/events","html_url":"https://github.com/DevinVinson/WordPress-Plugin-Boilerplate/issues/313","id":93368405,"number":313,"title":"Custom post type registration, with_front, and error 404","user":{"login":"grantpalin","id":183909,"avatar_url":"https://avatars.githubusercontent.com/u/183909?v=3","gravatar_id":"","url":"https://api.github.com/users/grantpalin","html_url":"https://github.com/grantpalin","followers_url":"https://api.github.com/users/grantpalin/followers","following_url":"https://api.github.com/users/grantpalin/following{/other_user}","gists_url":"https://api.github.com/users/grantpalin/gists{/gist_id}","starred_url":"https://api.github.com/users/grantpalin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grantpalin/subscriptions","organizations_url":"https://api.github.com/users/grantpalin/orgs","repos_url":"https://api.github.com/users/grantpalin/repos","events_url":"https://api.github.com/users/grantpalin/events{/privacy}","received_events_url":"https://api.github.com/users/grantpalin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-06T20:20:32Z","updated_at":"2016-01-29T19:26:31Z","closed_at":null,"body":"I'm using the boilerplate to implement a custom plugin for my own use. I've added code to register one custom post type and one custom taxonomy. I use a custom permalink structure for my posts, which my custom post type by default appears under. It works here - an instance does appear as expected when viewed from the front-end. To get around the permalink base, I tried adding `with_front => false` to the `rewrite` array; when I do this, there is no apparent error, but the same CPT entry generates a 404 error when viewed under the now-unprefixed permalink. Oddly, I have no issue with viewing the custom taxonomy archive. Also, the CPT archive listing does work - it's just the single view that does not.\r\n\r\nI've added below the relevant code blocks.\r\n\r\nIn the activator class:\r\n\r\n    public static function activate() {\r\n        require dirname(__FILE__) . 'taxonomies/class-projecting-tax.php';\r\n        $tax = new Projecting_Tax();\r\n        $tax->register_all();\r\n        \r\n        require dirname(__FILE__) . 'post_types/class-projecting-cpt.php';\r\n        $cpt = new Projecting_CPT();\r\n        $cpt->register_all();\r\n        \r\n        // flush rewrite rules for custom post types and taxonomies\r\n        flush_rewrite_rules();\r\n    }\r\n\r\nIn the orchestration class:\r\n\r\n    private function define_admin_hooks() {\r\n        // snip\r\n        \r\n        $tax = new Projecting_Tax();\r\n        $this->loader->add_action( 'init', $tax , 'register_all' );\r\n        \r\n        $post_types = new Projecting_CPT();\r\n        $this->loader->add_action( 'init', $post_types , 'register_all' );\r\n    }\r\n\r\nIn the CPT orchestration class:\r\n\r\n    public function register_all()\r\n    {\r\n        require_once 'class-projecting-cpt-project.php';\r\n        $cpt = new Projecting_CPT_Project();\r\n        $cpt->register();\r\n    }\r\n\r\nAnd in the CPT registration class:\r\n\r\n    function register() {\r\n        $args = array(\r\n            'label'               => __( 'project', 'projecting' ),\r\n            'description'         => __( 'Projects!', 'projecting' ),\r\n            'labels'              => array(\r\n                'name'                => _x( 'Projects', 'Post Type General Name', 'projecting' ),\r\n                'singular_name'       => _x( 'Project', 'Post Type Singular Name', 'projecting' ),\r\n                // snip\r\n            ),\r\n            'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', ),\r\n            'taxonomies'          => array( 'project_type' ),\r\n            'hierarchical'        => false,\r\n            'public'              => true,\r\n            'show_ui'             => true,\r\n            'show_in_menu'        => true,\r\n            'menu_position'       => 20,\r\n            'menu_icon'           => 'dashicons-portfolio',\r\n            'show_in_admin_bar'   => true,\r\n            'show_in_nav_menus'   => true,\r\n            'can_export'          => true,\r\n            'has_archive'         => 'projects', //archive slug\r\n            'exclude_from_search' => false,\r\n            'publicly_queryable'  => true,\r\n            'rewrite'             => array(\r\n                'slug'                => 'projects',\r\n                'with_front'          => false, // doesn't work, CPT instance 404s\r\n            ),\r\n            'capability_type'     => 'page',\r\n        );\r\n        \r\n        register_post_type( 'project', $args );\r\n    }\r\n\r\nApologies for all the code blocks, they seem the relevant ones to include. I'm still figuring out the boilerplate, it does seem to take some coordination effort to correctly register custom types/taxonomies.\r\n\r\nAgain, the CPT views correctly when `with_front` is left off or set to `true`, yet the same, with the updated permalink, 404s out when `with_front` is set to false.\r\n\r\n`http://.../blog/projects/projectname/` - OK\r\n`http://.../projects/projectname/` -> 404 error\r\n\r\nI could possibly live with updating my base custom permalink for posts (this artifact of the blog-only days is a nuisance at times) since I was thinking to do it anyway, but I'd like to know if there's a reason why the otherwise functional settings do not work here."},"comment":{"url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/comments/176924602","html_url":"https://github.com/DevinVinson/WordPress-Plugin-Boilerplate/issues/313#issuecomment-176924602","issue_url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/313","id":176924602,"user":{"login":"scrchhrpn","id":16628918,"avatar_url":"https://avatars.githubusercontent.com/u/16628918?v=3","gravatar_id":"","url":"https://api.github.com/users/scrchhrpn","html_url":"https://github.com/scrchhrpn","followers_url":"https://api.github.com/users/scrchhrpn/followers","following_url":"https://api.github.com/users/scrchhrpn/following{/other_user}","gists_url":"https://api.github.com/users/scrchhrpn/gists{/gist_id}","starred_url":"https://api.github.com/users/scrchhrpn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrchhrpn/subscriptions","organizations_url":"https://api.github.com/users/scrchhrpn/orgs","repos_url":"https://api.github.com/users/scrchhrpn/repos","events_url":"https://api.github.com/users/scrchhrpn/events{/privacy}","received_events_url":"https://api.github.com/users/scrchhrpn/received_events","type":"User","site_admin":false},"created_at":"2016-01-29T19:26:31Z","updated_at":"2016-01-29T19:26:31Z","body":"I have same problem too. Actually, where is the best place or file in boilerplate to put function of register post type, calling that function from activate, flush_rewrite_rules and then add_action it?\r\nI have tried with the static function that regist cpt, and put it in class-plugin-name-admin, and everthing fine without 404. but i want to avoid static function to do that.\r\nCan you give the example how to put CPT and flush_rewrite_rules in a good way please?\r\nThanks."}}