Template single Custom Post Type - get 404

Hi everyone.
I created a new CPT with the post_type as match and I tried it into a loop in my template-landing and everything is fine.
Now I need to create the single-page of the match so I did this:

  1. copied and pasted single.php and changed the name as single-match.php, and inside this I changed the path of the get_template_part to the new content-single-match.php

  2. copied and pasted templates/content-single.php and changed the name as templates/content-single-match.php

Now everything should be fine but if I open the single page of the CPT I get a 404 error.
Can anyone see any error?

Did you try https://codex.wordpress.org/Function_Reference/flush_rewrite_rules?

Re-saving your permalink options at /wp-admin/options-permalink.php should also do it.


That did the trick.
Why did it happen? I mean, I didn’t set anywhere any option about the permalinks, now I set them as “post-name” and everything works.

Because you didn’t flush the rewrite rules after post type registration.

Re-saving your permalink options (the specific settings aren’t relevant) is a quick way to flush them w/o calling flush_rewrite_rules in your code.

Also, this is standard WordPress stuff, unrelated to Sage.

1 Like