Glenn
Forum Replies Created
-
Hi Dolson,
Thanks for your response. I understand taking that route and enabling PHP templating is recommended. However my child theme runs on a parent theme that takes over the standard loop inside single.php. It would add a lot of unnessaccary work to diverge from that. All I really need are two field values (the event location and more info URL). I should be able to access this meta data based on the post ID just like with any other post type correct? Normally I would be able to find this data located in the meta data array associated with the post or ACF data. However, I can’t locate this event data I mentioned in these places. I would appreciate some direction here as to how I could find this without going your recommended route.
Thank you so much!
In case anyone is encountering a similar situation. I have found a solution for it!
Here’s what you have to do.
1. Create a js file in your theme directory and enqueue in the wp-admin head
add_action('admin_enqueue_scripts', 'enqueue_admin_scripts') ; function enqueue_admin_scripts() { wp_enqueue_script('gutenberg-filters', get_stylesheet_directory_uri() . '/js/filter-gutenberg-blocks.js', ['wp-edit-post']); }
2. Add the following code to this js file.
const coreBlocksArray = ['core/paragraph', 'core/heading', 'core/list', 'acf/button']; function addParentAttribute( settings, name ) { if ( !coreBlocksArray.includes(name) ) { return settings; } return Object.assign(settings, { parent: [ 'acf/img-text-column', 'acf/img-text-row', 'acf/text-block', ], } ); } wp.hooks.addFilter( 'blocks.registerBlockType', 'my-plugin/class-names/list-block', addParentAttribute );
First I created an array called ‘coreBlocksArray’ containing all blocks that I want to target. This includes a few WordPress core blocks and a custom block that I created with Advanced Custom Fields (ACF).
In the function below, it looks at every block in the array and adds the ‘parent’ attribute to settings. More about the Block Configuration ‘parent’ attribute in the Block Registration Documentation.
It’s adding a selection of custom blocks (acf/img-text-column, acf/img-text-row, acf/text-block) to this ‘parent’ array.
This means that the blocks inside the ‘coreBlocksArray’ array are now only available inside the selection of custom blocks.
I hope this helps anyone!