Home Forums Gutenberg ACF Field Data in Block (HTML) Template Reply To: ACF Field Data in Block (HTML) Template

  • @chandlerwarren I have a hack that’s working for me in the short term before I delve into looking at the feasibility of creating a native Gutenberg block or an ACF block to get a better solution.

    What I have done:

    • Created a separate .HTML template in the templates folder of my child theme folder based on single.html. Let’s say single-event.html (based on my Custom Post Type).
    • Created an empty template part in parts. Let’s say it’s called event-detail.html.
    • Then in my single-event.html template I have
      <!-- wp:template-part {"slug":"event-detail"} /-->
      where I want to render the ACF data.
    • Then from the site editor, I edit the new template part and insert a shortcode.
    • In my plugin (or in functions.php) it’s easy to add the shortcode code to use the global $post to then fetch the ACF fields and return a nice layout of my ACF fields.
      Not elegant, and probably not the preferred method. I’d like to find out how to do this properly.