❌

Reading view

Trying to create blocks from ACF fields to use in a custom post type template

Goal: create a resource directory built on a custom post using an ACF custom field group with a FSE template.

Completed so far: Resource custom post type; Resource detail fields (resource_logo, resource_descriptio, resource_personal_impact)

I created a sample resource with the title and these fields populated.

I have created the following code with the help of AI to create the blocks. The blocks are showing up on the editor, but have no shape when added to the template. They also do not render content on the published page.

add_action('acf/init', function() { // Resource Logo Block acf_register_block_type([ 'name' => 'resource_logo', 'title' => __('Resource Logo'), 'description' => __('Displays the resource_logo ACF image field'), 'render_callback' => 'acf_block_render_resource_logo', 'category' => 'media', 'icon' => 'format-image', 'supports' => ['align' => false], ]); }); // Render Callbacks function acf_block_render_resource_logo() { $logo = get_field('resource_logo'); if ($logo) { echo wp_get_attachment_image( $logo['ID'], 'full', false, ['alt' => esc_attr($logo['alt'])] ); } } 

This is my first attempt at something like this. I want to try to do this without additional plugins (this subreddit has influenced me).

I feel I am missing something obvious. If I need rtfm, point me in the right direction because I stuck at the moment. Let me know if I need to provide more details. Thanks!

submitted by /u/Wheels-13756
[link] [comments]
  •  
❌