Skip to main content
19 events
when toggle format what by license comment
Sep 23, 2022 at 9:22 comment added gtamborero This may work but it's a hacking WordPress aproach. The right answer is Step 1 of Matt Keys: Just define correctly the post type when registering it: register_post_type( 'custom_post_type', array( 'rewrite' => false ) );
Aug 20, 2021 at 1:48 comment added Philarmon Ahh, finally a solution - thank you! I was wondering why I am suddenly getting 404s for an hour before realizing it was because of this 'rewrite' => array( 'slug' => false) thing :)
Jul 9, 2021 at 20:17 vote accept Ben Racicot
Dec 10, 2020 at 6:38 comment added user9437856 It's working for me.
Jul 2, 2020 at 8:07 comment added Swaranan Singha Barman It worked for single post type. How to use the code for multiple post type?
May 4, 2020 at 12:58 comment added Gediminas I have been using this nice code until WP 5.2 came. After the update this code starts to fail on my Custom Post Type plugin and Advanced Custom Fields plugin, because, I think, they are using the same pre_get_posts function, so instead of Advanced Custom Field Groups I see my custom posts in this plugin... Also fails with CPT UI plugin - can not create new posts anymore, they are not appearing in list after creating them. Please help!!
Apr 3, 2020 at 16:28 comment added PhpDoe For those who have a problem with the code above, it works like a charm if you replace the second function ( function na_parse_request() ) by the one found on this answer. Dont forget to modify the code with your own Custom Post Type name.
Jan 5, 2020 at 13:24 comment added Saleh Mahmood single-{cpt}.php stops working using this approach
Jun 14, 2019 at 20:26 comment added Marco Miltenburg This code assumes that the post_type name is the same as the custom post type slug which doesn't necessarily have to be in every case. But for the rest, great solution although I agree a native WP solution would be better.
Oct 8, 2018 at 0:10 comment added Radley Sustaire This solution unfortunately caused some broken links and my blog stopped showing posts and was just a normal page. See a better solution below by Matt Keys.
Jan 2, 2018 at 12:14 review Suggested edits
Jan 2, 2018 at 14:01
Jul 18, 2017 at 18:53 comment added rob-gordon Is it just me or does this break some wordpress conditional tags like is_single() and is_singular()?
Jul 18, 2017 at 0:13 comment added Ben Racicot We need something better than this. Support to remove the slug built in so that we cannot create conflicting URLs later on. The way regular posts and pages create their URLs.
Nov 8, 2016 at 12:25 comment added Fabio Montefuscolo It fails with nginx because the condition 2 != count( $query->query ). With nginx, you can have $query->query as array('page' => '', 'name' => '...', 'q' => '...'). So @NateAllen, what is the meaning of that condition?
Jan 25, 2016 at 11:29 comment added Abin can you please update, how to use this code for multiple post types
Oct 8, 2015 at 19:07 history bounty ended CommunityBot
Oct 1, 2015 at 13:53 comment added Nate Allen I think this is a good automated solution if you're confident that you won't be creating conflicts. This isn't a good solution if you're providing this to... let's say a client that isn't tech savvy.
Oct 1, 2015 at 13:29 comment added Ben Racicot thanks. Do you think this is better than creating the rewrites manually? I've seen that solution and it may keep the conflicts you mention at bay?
Sep 30, 2015 at 20:45 history answered Nate Allen CC BY-SA 3.0