Home Forums Gutenberg ACF code in a block template


ACF code in a block template

  • I have created a custom post type called features and have added a few fields and then created a few posts of that type to test. If I write a wp_query loop to query that content type and output the fields in the standard page template file then it works as expected and outputs the data correctly.

    I didnt however want to have a chunk of the data at a pre determined spot in the template file however. I wanted the user to be able to insert the chunk in between standard gutenberg blocks. So they may choose to have a paragrah, then an image, then insert the acf content block and then another paragraph. What I decided to do was to create a new block type with acf_register_block_type but I would not add any fields directly to that block type and instead leave it empty and in the template file for that block, i would insert my wp_query code to output my content type data. The issue is that when i output the_title, the content type posts title is output but any other acf field I have attached to the content type doesnt output and I am unsure why.

  • I have now resolved the issue, I needed to add , get_the_ID() to the end of each field to make sure it was associated with the current page id and then it was fine.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.