Last active
July 4, 2024 03:14
-
-
Save gh640/21cc5caf290397addb25a84840436508 to your computer and use it in GitHub Desktop.
WordPress: Usage of Block Bindings API for custom fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- wp:paragraph { | |
"metadata":{ | |
"bindings":{ | |
"content":{ | |
"source":"core/post-meta", | |
"args":{ | |
"key":"book-genre" | |
} | |
} | |
} | |
} | |
} --> | |
<p></p> | |
<!-- /wp:paragraph --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'init', function () { | |
register_meta( | |
'post', | |
'book-genre', | |
[ | |
'show_in_rest' => true, | |
'single' => true, | |
'type' => 'string', | |
'default' => 'Default text field', | |
] | |
); | |
register_meta( | |
'post', | |
'book-author', | |
[ | |
'show_in_rest' => true, | |
'single' => true, | |
'type' => 'string', | |
'default' => 'Default text field', | |
] | |
); | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- wp:columns --> | |
<div class="wp-block-columns"><!-- wp:column {"width":"100%"} --> | |
<div class="wp-block-column" style="flex-basis:100%"><!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"book-genre"}},"__default":{"source":"core/pattern-overrides"}},"name":"Genre"}} --> | |
<p></p> | |
<!-- /wp:paragraph --></div> | |
<!-- /wp:column --> | |
<!-- wp:column --> | |
<div class="wp-block-column"><!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"book-author"}},"__default":{"source":"core/pattern-overrides"}},"name":"Author"}} --> | |
<p></p> | |
<!-- /wp:paragraph --></div> | |
<!-- /wp:column --></div> | |
<!-- /wp:columns --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Other resources (Japanese):