Skip to main content
2 of 11
added 469 characters in body

How do I save meta key value in the save function?

The edit code saves the heading value in meta. How do I save it in the save function?

The render_callback is as below. I tried passing "render": "file: path-to/php.php" in block.json but it doesn't work.

function register_latest_post_property_item() {
    register_block_type("create-block/property-items", [ "render_callback" => "render_latest_post_property_item"
    ]);
}
add_action("plugins_loaded", "register_latest_post_property_item");

function render_latest_post_property_item( $value, $object, $field_name ) {

Edit function

import { __ } from '@wordpress/i18n';
import { useEntityProp } from "@wordpress/core-data";
import { useSelect } from "@wordpress/data";
const {
    TextControl,

} = wp.components;


import { useBlockProps } from '@wordpress/block-editor';

import './editor.scss';


export default function Edit(props) {

const [meta, setMeta] = useEntityProp("postType", "properties", "meta");

const heading = meta["heading"];

const onChangeheading = (newValue) => {
    setMeta({ ...meta, heading: newValue });
    
};



return (
    <div {...useBlockProps()}>
        
        <div>
            <TextControl
                tagName="h1"
                label="Property title"
                className="card-title"
                value={heading}
                onChange={onChangeheading}
            />
        </div>
    </div>
);
}