WP Query by Gutenberg block and get its attribute

After hours of googling I came up with following solution. Maybe once will help to someone. 1) query post where is used gutenberg youtube block: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘s’ => ‘core-embed/youtube’, ‘posts_per_page’ => 1 ); $query = new WP_Query($args); 2) extract the URL from youtube block of the post … Read more

The editor has encountered an unexpected error. // TypeError: Cannot read property ‘prefix’ of null

So, I was researching this topic a bit deeper. All answers found on this SE suggested disabling Gutenberg with a plugin. This couldn’t be a valid “fix” in my oppinion. After researching and browsing through the git issues of WordPress/gutenberg I’ve found a pretty easy solution for this problem. The user joshuafredrickson on the git … Read more

Shortcode to Gutenberg-block: additional text on front-end and conditional display

Although a little different than I had initially anticipated, I have found/created a solution to my two problems. Conditionals I have opted to move non-required input to the sidebar, using the InspectorControls-element. Reason for this is that I realised that it would be impossible to hide a field (in the editor-part of the screen) that … Read more

Filter post_content before loading in Gutenberg editor

I found that there is no way to change the data which is coming to editor when it is loaded. But it’s possible to replace the data after that. JS: script.js wp.domReady(function () { const newData = window.myNewBlocksData; if (newData) { wp.data.dispatch(‘core/block-editor’).resetBlocks(wp.blocks.parse(newData)); console.log(‘replaced’); } }) PHP: <?php class MyBlocksManipulation { public $prefix = ‘my’; public … Read more

WordPress Gutenberg-Block with ESNext (withState, withSelect)

Okay guys, I’ve got a solution: import {withSelect} from ‘@wordpress/data’; import {SelectControl} from “@wordpress/components”; import ReactSpinner from ‘react-bootstrap-spinner’ import ServerSideRender from ‘@wordpress/server-side-render’; const MySelectControl = ( ({chart, setAttributes, …props}) => ( <SelectControl label=”Bitte wählen Sie ein Diagramm aus: ” value={chart ? parseInt(chart) : 0} options={props.options} onChange={(chart) => { setAttributes({ chart: chart }); }} /> ) … Read more