Archived topic
Struggling with Custom Post type
4 replies · Started by rikdol on May 12, 2021
It all seemed like a one two three thing. but i can't for the life of me get my custom post type to work.
im using the plugin 'custom post type ui'
i've created a cpt called: 'cb_chromebooks' . label plural is the same, label single is 'cb_chromebook'. I haven't touched any other settings in this cpt. i then went to tools and copied the code from 'all Custom Post Type UI posttypes' and pasted it into the functions.php
i have an ACF group called cb_chromebook_acfgroup. in this group i've added the rule: post type > equals > cb_chromebook ( as this singular form was what i could select from the drop down ).
i've then followed the instructions here: https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/ ( updated may5th ) meaning i did the following:
<li>copied 'single.php' and renamed the new file to 'cb_chromebooks.php'</li>
<li>copied 'content-single.php' and renamed the copy: 'content-cb_chromebooks.php'</li>
in the original files: single.php and content-single.php i added an echo telling me what file was used on the frontend to show the content. i added: Echo "current file single.php"; just before the comment: 'generate_after_primary_content_area_hook'
i did the same for the other 3 files, (added an echo there so i knew what was being loaded.)
i then opened the 'cb_chromebooks.php' file and changed the following:
`<li>old line: 'generate_do_template_part( 'single' );'</li>
<li>new line: 'get_template_part( 'content', 'cb_chromebooks' );'</li>`
i manually created a post from the new custom post type, can be found here: https://www.chromeo.nl/cb_chromebooks/test-cb_chromebooks/
On the frontend it shows that it used 'content-single.php'. What am i missing? because i'm stuck not being able to use the php that i need to create the content.
i have created a temporary user for support to use if need be.
Thanks to a colleague who mentioned that i should try removing the underscore from the name i have it working. https://www.chromeo.nl/cptchromebook/testcptchromebook/
but i've also done something else different. instead of following the doc and changing single.php to cpt.php, i changed it from single.php to single-cpt.php. After that i was able to edit the line into ('content','cpt') and it worked.
That second part is probably what made it work, instead of the underscore but i haven't tested this.
This kind of threw me off, since i had no idea that could be the issue. Could the information in the doc miss this renaming convention? or should this have worked as written?
Hi here,
glad to hear you got it working - yes, i was meant to update the docs as that second change is correct. We'll get that updated asap!
I saw that the doc was updated. this is working for me now. Thanks David
Awesome - thanks for letting us know!