I have created a custom block use the blocks API. I am using useEntityProp
to get/set post meta. This works fine on my dev server but on the live server useEntityProp
is returning undefined.
Here is my edit file (console.log(meta) returns undefined) :
import { __ } from "@wordpress/i18n";
import { MediaUpload, useBlockProps } from "@wordpress/block-editor";
import { useEntityProp } from "@wordpress/core-data";
import { Button } from "@wordpress/components";
const Edit = (props) => {
let {
attributes: { foundFeatures, features, gallery, itinerary, duration },
setAttributes,
context: { postType, postId },
} = props;
let [meta, updateMeta] = useEntityProp("postType", postType, "meta", postId);
The context is returning the correct post type and post id.
And I am registering the post meta enabling the show_in_rest
option
register_post_meta(
'tour-collection',
'locations',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
)
);
You need to add custom-fields to the supports argument when creating the post type.