Skip to content
Chris Zarate edited this page Apr 20, 2019 · 1 revision

Filter examples

Populate connections with graphql_blocks_output

/**
 * Create a MediaItem connection to core/image blocks.
 */
function add_post_connections( $blocks, $post ) {
	return array_map( function ( $block ) {
		if ( 'core/image' === $block['type'] ) {
			if ( isset( $block['attributes_raw']['id'] ) ) {
				$block['connections'][] = get_post( $block['attributes_raw']['id'] );
			}
		}

		return $block;
	}, $blocks );
}
add_filter( 'graphql_blocks_output', 'add_post_connections', 10, 2 );
Clone this wiki locally