Custom post type are not appearing on archive page and single page. Even when using archive-post_type.php and single-post_type.php? When you preview post it shows “not found” or “404 error” ? How to show custom post types? There may be a lot of reasons for custom posts not being shown.
Here we are going to check for possible reasons for this. These may be because of using wrong code in functions.php or something that is really unexpected.
Possible reasons for custom post types not being shown are :
1. First reason can be that you have not used ‘post_type’ in your query.
To use it in your query follow :
$the_query = new WP_Query( array( 'post_type' => 'tutorial', 'posts_per_page' => '10' ));
while( $the_query->have_posts() ): $the_query->the_post();
2. Set ‘has_archive’ as true when registering custom post type.
see How to add custom post types in wordpress ? for complete structure.
3. If you want these to be shown with different layout:
Please keep in mind that custom post types are not shown with regular posts. You have to modify query or use different pages. Suppose you have create custom post type “Products”. You will need to create page archive-products.php and single-products.php. So we have to use archive-post_type.php and single-post_type.php . here post_type represents slug of custom post type.
4. If using archive-post_type.php and single-post_type.php follow this:
Go to admin panel and select “permalinks” under “settings”. Now select “custom structure” option and paste /%category%/%postname%/ in it. See image below:
After updating this revert back to your original / earlier setting for permalinks. By reverting I am referring to update to option selected before we made this particular change. Now check your posts if they are being shown.
Still facing problems? Feel free to discuss your problem via comments. I will be happy to help!