Archived topic
ACF & Custom Post Type: Should I use hooks or custom post template?
5 replies · Started by Alexander on April 10, 2021
Hi there,
I have created a custom post type (via the plugin CPT UI) and now use custom fields for that specific post type.
How do I ideally show them via the front end? Should I go with hooks or would it be beneficial to use a custom post type template (as described here).
All posts in that post type will be quite unique from other posts, with their own content and quite a lot data in the custom fields. I feel that a lot of support answers here in the forum tend to use hooks > custom template, but I wonder whether this advise holds true if that specific post type is quite unique.
Looking forward to your thoughts,
Alex
Hi there,
for very unique requirements it would be best to use a CPT Template.
If you want to keep the template structure that GP uses you can build off a copy of those templates. This article provides a simple method for doing that:
https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/
Thanks for your quick help, David.
I just did as instructed and somehow I can't get it to work.
Somehow the information here and here is conflicting.
Assuming the custom post type is called 'project', do I need to create an individual file called:
single-project.php
or those two:
project.php and content-project.php
Somehow, if I do the latter (as explained in your support article) my custom post does not pick up any changes done to the template.
UPDATE/
I just found this support article and feel that I simply need to use:
get_template_part( ‘content’, ‘project’ );
Instead of:
generate_do_template_part( 'project' );
Thanks,
Alex
Aah theres actually a typo in that doc - ill get the corrected.
First thing to do is to copy the GP single.php and content-single.php templates to your Child Theme.
Then rename them to:
single-cptname.php
content-cptname.php
replace the cptname in those filenames with that of your custom post type.
you can then update the HTML within the content-cptname.php to display whatever it is you need from your CPT.
Yes, that helped. Thank you, David!
But in addition, I also need to do this, or (as I am using a child theme)?
Use:
get_template_part( ‘content’, ‘project’ );
Instead of:
generate_do_template_part( ‘project’ );
You should use:
generate_do_template_part( ‘project’ );
Its a GP Custom function for the get_template_part - does a similar thing but has some extra functionality.