Support

Account

Home Forums ACF PRO Getting Field from Block

Unread

Getting Field from Block

  • This is how i’m currently grabbing specific Field Data from a Block, just want to know it’s the ‘right’ way or not.

    // Get the post_content, parse post_content & return all the blocks
    $post_content = get_the_content( get_the_ID() );
    $blocks = parse_blocks( $post_content );
    
    // Start & End Dates from ACF Fields
    $acf_project_location = $blocks[0]['attrs']['data']['project_location'];
    $acf_start_date = $blocks[0]['attrs']['data']['start_date'];
    $acf_end_date = $blocks[0]['attrs']['data']['end_date'];

    Any feedback would be greatly appreciated.

Viewing 1 post (of 1 total)

The topic ‘Getting Field from Block’ is closed to new replies.