Categories
CMS Mastering Development Wordpress

Multiple Select on Gutenberg Sidebar as metakey

I want to show a multiple select element in the sidebar when editing a page in admin, where I can save the selected values in a metakey. Of course also load the selected values upon load of page-edit in admin. I manage to show the list, but I don’t know how to save it i […]

Categories
CMS Mastering Development Wordpress

Rich text (gutenberg) block not updating meta field

I want to save some HTML to my meta data using the rich text component. If the key does not exist, the rich text will create and save the key and value no issues. It will save edits as required; no issues as long as the page has not been re-loaded. When the page is […]

Categories
CMS Mastering Development Wordpress

Issue migrating a checkbox-type meta field to the block editor

I’m trying to add Gutenberg support to a plugin that registers a custom post type with a checkbox-type meta field called _meta_restrict, while maintaining back-compatibility with the classic editor at the same time. I’ve made some progress but I’m stuck now and need a bit of help. This is the relevant code I’m using to […]

Categories
CMS Mastering Development Wordpress

Issue migrating a checkbox-type meta field to the block editor

I’m trying to add Gutenberg support to a plugin which uses a checkbox-type meta field called _meta_restrict, while maintaining back-compatibility with the classic editor at the same time. I’ve made some progress but I’m stuck now and need a bit of help. This is the relevant code I’m using to register and save the meta […]

Categories
CMS Mastering Development Wordpress

Gutenberg default initial values for FocalPointPicker

I am trying use <FocalPointPicker /> in <PluginDocumentSettingPanel /> and almost everything working as it should, but I have troubles when creating a new post. I am getting this warning: Warning: Received NaN for the value attribute. As I understand it occur because post meta isn’t created yet. I solved this by adding update_post_meta during […]

Categories
CMS Mastering Development Wordpress

How to save a ToggleControl value in a meta field?

I registered a meta field called _meta_restrict in a custom post type: PHP: function register_meta_fields() { register_post_meta( ‘custom_post_type’, ‘_meta_restrict’, array( ‘show_in_rest’ => true, ‘single’ => true, ‘type’ => ‘boolean’, ‘auth_callback’ => function() { return current_user_can( ‘edit_posts’ ); } ) ); } add_action( ‘init’, ‘register_meta_fields’ ); JS: let RestrictControl = ({ restrict, onUpdateRestrict }) => ( […]

Categories
CMS Mastering Development Wordpress

Custom Meta Box not Saving in Posts with Gutenberg Editor

I’ve read quite a bit of documentation around it, tons of other answers here, but I can’t seem to discern why the custom meta box I’m trying to add to posts (and pages, but let’s start with one at a time) isn’t saving the post meta. I’ve got a custom CPT and it works perfectly. […]

Categories
CMS Mastering Development Wordpress

Saving Metadata from the Gutenberg Editor Sidebar to the Database

In the saga so far, you can see my First post/question Second post/question This is my third (and hopefully final) question. I’ve got everything working except for saving the data in the WP database. Incidentally, this tutorial is a goldmine for an understanding of how things work in the new Gutenberg way, and how all […]

Categories
CMS Development Wordpress

How to register meta field with checkbox to REST API with default value true?

I have a meta field with checkbox, it has by default checked value, but when I register it to REST API my checkbox become unchecked. How can I get it checked by default? Here is my code for metabox: function modest_gutenberg_meta_add_meta_box() { $post_types = array(‘post’, ‘page’, ‘modest_portfolio’); foreach ($post_types as $post_type) { add_meta_box( ‘modest_gutenberg_meta_post_title_option’, esc_html__( […]

Categories
CMS Development Wordpress

Gutenberg: register_block_type -> render_callback function – trigger script

I’ve got a problem while rendering / updating a Gutenberg block. For adding the Gutenberg block I use the following code snippet: defined(‘ABSPATH’) || exit; function my_charts_importer_charts_render_callback($attributes, $content) { $post_id = $attributes[‘chart’]; $chart_json = get_field(‘chart_json’, $post_id); $chart_container = get_field(‘chart_container’, $post_id); $output = ‘<script>’ . ‘document.addEventListener(“DOMContentLoaded”, function () { let myChart = ‘ . $chart_json . […]