0

In register_post_type, I can register a custom post type and set parameters, including rewrite. Based on https://developer.wordpress.org/reference/functions/register_post_type/#rewrite, if it set to true, then the rewrite for this type of post will be handled.

Then I add some rewrite rules for the custom type of post by invoking add_rewrite_rule in custom_rewrite_basic function.

However, on my tests, I find even I set rewrite to false, the rule set by add_rewrite_rule will still work, why?

2

That's not what the rewrite argument of register_post_type means. If you set it to false, that doesn't mean "prevent any rewriting of this post type's URL, ever." That wouldn't even be possible.

It simply means not to use pretty permalinks when the post is created. You can still add rewrite rules for that post type later.

1
  • As a clarification, pretty permalinks are still possible, but the default ones core adds for your post type are not added when it is set to false. This does not prevent new rewrite rules that refer to your post type from being created, or ugly permalinks being used.
    – Tom J Nowell
    Oct 12 '21 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.