-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
When a block or template is deleted, the postmeta is not deleted. This is an issue because in templates, the data will be retrieved using get_post_meta.
Reproduce:
- make a template
- make a post, fill out the template and save
- go back into the post, delete the block then save
You can keep an eye on the postmeta table to see that it's still there or put a filter on the content to view it (at the bottom)
There are a couple of ways of fixing:
- delete postmeta on block deletion and delete all instances of the meta_keys used in a template on template deletion (so as not to leave orphaned uneditable/undeletable data)
- use a dynamic render which won't show the postmeta data unless the block is there
I think the first is the way to go as it avoids the orphaned data issue.
Cheap and cheerful content filter:
function mjj_filter_content( $content ){
$post_id = get_the_ID();
if( empty( $post_id ) ){
return $content;
}
$gcf_postmeta = get_post_meta( $post_id, 'main field', true );
if( empty( $gcf_postmeta ) ){
return $content;
}
return '<h2>' . print_r( $gcf_postmeta, true ) . '</h2>' . $content;
}
add_filter( 'the_content', 'mjj_filter_content' );
Metadata
Metadata
Assignees
Labels
No labels