- This topic has 8 replies, 3 voices, and was last updated 4 years, 1 month ago by
David.
-
AuthorPosts
-
February 23, 2022 at 1:16 pm #2131083
Filip
Hi!
I’m creating a Case study custom post type for my website and I’m lost.
I tried following your tutorial but it’s still not working.
I’ve added this code to my child theme’s functions.php:
function create_post_type() {
register_post_type(‘case-study’,
array(
‘labels’ => array(
‘name’ => __(‘Case studies’, ‘textdomain’),
‘singular_name’ => __(‘Case study’, ‘textdomain’),
),
‘public’ => true,
‘has_archive’ => true,
)
);
}add_action(‘init’, ‘create_post_type’);
I’ve also downloaded a copy of single.php and content-single.php, renamed them to single-case-study.php and content-case-study.php and uploaded them in my child theme’s folder.
I’ve replaced the code in a single-case-study.php (line 29) with the one you provided:
get_template_part( ‘content’, ‘project’ );
The thing is – I can add the case studies in the WP dashboard, but I can’t view them and see the archives (404 errors).
Please help, thanks!
February 23, 2022 at 1:32 pm #2131101Ying
StaffCustomer SupportHi there,
You need to replace the
projectwith your custom post type name inget_template_part( 'content', 'project' );In your case,
case-study.February 23, 2022 at 2:08 pm #2131131Filip
Oh, I’ve replaced that too, just as you said (accidentally pasted the default line in the original post).
February 23, 2022 at 2:51 pm #2131167Ying
StaffCustomer SupportCan you try change permalinks setting to post name to test?
The setting can be found at dashboard > settings > permalinks
February 24, 2022 at 2:07 am #2131558Filip
It works now.
Thanks so much!
February 24, 2022 at 3:18 am #2131613Filip
Everything’s perfect but there’s still one more issue.
I’ve applied the same template for a blog post and a case study – but the width of the content for the case study CPT is not applied.
Here’s the image.
1st img – post
2nd img – case study
3rd img – content settings applied to bothFebruary 24, 2022 at 3:43 am #2131640David
StaffCustomer SupportHi there,
change:
get_template_part( 'content', 'case-study' );to:
generate_do_template_part( 'case-study' );February 24, 2022 at 3:54 am #2131663Filip
Works fine now, thanks once more!
February 24, 2022 at 4:16 am #2131675David
StaffCustomer SupportGlad to hear that!
-
AuthorPosts
- You must be logged in to reply to this topic.