Created
December 17, 2020 20:06
-
-
Save yesnosurely/99113ba6fd2e9cd5810ff9111d36e27c to your computer and use it in GitHub Desktop.
get acf field from gutenberg block [php, wp, acf, wordpress]
This file contains hidden or 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 | |
| function get_field_from_block($post_id, $block_name, $field_name){ | |
| $block_name = 'acf/' . $block_name; | |
| $post = get_post($post_id); | |
| if ( has_blocks( $post->post_content ) ) { | |
| $blocks = parse_blocks( $post->post_content ); | |
| foreach ($blocks as $block){ | |
| if ($block['attrs']['name'] == $block_name){ | |
| $data = $block['attrs']['data'][$field_name]; | |
| break; | |
| } | |
| } | |
| } | |
| return $data; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment