Archived topic
Creating custom template for Custom Post Type and Advanced Custom Fields
5 replies · Started by Nadine on May 11, 2020
I have a custom post type and advanced custom fields for that post type. I need to create a custom template to call that CPT and the custom fields. I searched but could not find a tutorial anywhere for this. How would I go about doing this? Also, do I need to add anything to my functions file to recognize ACF?
Thanks!
Hi there,
What kind of template are trying to build? What are the custom fields doing?
You could copy one of the parent templates (page.php for example) and add it to your child theme. Then you just need to name it properly: https://developer.wordpress.org/themes/template-files-section/page-template-files/
Or, depending on what you're wanting to do, you can use our Hook Elements to hook your custom fields into the existing templates: https://docs.generatepress.com/article/hooks-element-overview/
You shouldn't need to add anything to your functions file to recognize ACF.
The page or archive is going to be a search form that returns the CPT + ACF on the same page. The ACF is just additional info. for the CPT - location, phone, website, etc.
In that case, I would copy the index.php file in the parent theme and add it to your child theme. Re-name it as a custom page template (https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use) or as a CPT archive (https://developer.wordpress.org/themes/template-files-section/custom-post-type-template-files/).
Then you can adjust the file as needed :)
ok thanks!
You're welcome :)