0

I tried to set up a custom post type in Wordpress, and everything worked just fine.

Until displaying a single post from my custom post type. First it didn't automatically use the single.php (as it should), and then I tried to create a custom single-{custom_post_type}.php but it doesn't even use that one :/

I'm kind of confused now.

//Edit:

Solved the problem. Just had to add flush_rewrite_rules(); after register post type in functions.php

register_post_type( 'communitydeals' , $args );
flush_rewrite_rules();
2
  • 3
    You should do that only once, and then remove it. flush_rewrite_rules() are expensive to run on every page load Commented Nov 10, 2015 at 9:45
  • 1
    You even shouldn't use flush_rewrite_rules() in your theme, it is not in theme scope, You can write and small plugin and use this code add_action( 'after_switch_theme', 'flush_rewrite_rules' ); to flush rewrite rule for custom post type only when you change theme . Or only updating permalink structure once from Admin Menu >> Settings >> Permalinks will make it work fine there too.
    – Shaon
    Commented Nov 10, 2015 at 10:09

2 Answers 2

0

First Didn't did you create custom post type page?

Example i have a custom post type called compute i will create a file called compute.php and single-compute.php and write your code for multiple posts in compute.php and single post in single-compute.php if you still not showing or showing file not found try to logout your site and delete browser history and open in another browser try to login hope this would help :-)

0

Solved the problem. Just had to add flush_rewrite_rules(); after register post type in functions.php:

register_post_type( 'communitydeals' , $args );
flush_rewrite_rules();
1
  • You don't want to call flush_rewrite_rules() on every page load!
    – birgire
    Commented Dec 26, 2015 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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