tshingleton
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Loading a default pattern per custom post type@leifer
This is exactly what I was looking for! Implemented and works great!
Thanks for taking the time to figure this one out and shareForum: Developing with WordPress
In reply to: Loading a default pattern per custom post type@leifer Thanks for sharing the workaround! I may have to go this route, if I can’t find a solution here.
Ideally, would be great to allow editors to edit patterns on the backend and having that update as appropriate, vs using the importer.
Forum: Developing with WordPress
In reply to: Loading a default pattern per custom post typeThanks @mdshak! This got me very close. A few things:
– I had to reference ‘$post->post->post_type’ instead of ‘$post->post_type’ in the conditional, as the latter threw an undefined error — this appears to be working now
– I’m getting the WSOD (wp_debug on, no errors printed on screen) if I’m using the full code snippet. I commented out the line of code that I determined is the culprit. Running as is of course means the code does nothing; I need to uncomment and solve for that line if no one can beat me to it!
– Confirmed that ‘2601’ corresponds to the ID of a pattern on my site
Thank you again for the help! Anyone interested in taking a shot at solving this would be appreciated!
Here’s the code right now:/* * Load custom patterns per post type */ function load_post_type_patterns( $editor_settings, $post ) { if ( 'book' === $post->post->post_type ) { // Define an initial pattern for the 'Book' post type $editor_settings['__experimentalFeatures']['unfilteredTemplates']['book_template'] = array( array( 'title' => 'Book Template', 'content' => array( array( 'core/block', array( 'ref' => 2601, // The ID of your custom pattern ), ), ), ), ); //$editor_settings['template'] = 'book_template'; } return $editor_settings; } add_filter( 'block_editor_settings_all', 'load_post_type_patterns', 10, 2 );
- This reply was modified 11 months, 3 weeks ago by tshingleton.