Hello,
I have 2 post types Team and Events, Team has a block called events where you can select events (repeater) and Events has a block where you can select Team members (repeater). I am trying to on save of Team or Events to update the block on the other CPT to have the the new ID of the post you are saving, I can’t find anything online that will help me accomplish this, My code is below and i can get the block on the other CPT fine but i am unsure on how to update that block any help would be greatly appreciated
add_action( 'save_post_team', array( $self, 'save_person_to_event' ), 10, 3 );
public function save_person_to_event( $post_id, $post, $update ) {
if ( has_blocks( $post->post_content ) ) {
$person_blocks = parse_blocks( $post->post_content );
foreach ( $person_blocks as $key => $block ) {
if ( 'acf/events-feed-slider' === $block['blockName'] ) {
$events_field = $block['attrs']['data']['events'];
if ( $events_field ) {
for ( $i = 0; $i < $events_field; $i++ ) {
$event_id = $block['attrs']['data'][ 'events_' . $i . '_event' ];
var_dump($event_id);
if ( (int) $event_id ) {
$event_post = get_post( $event_id );
if ( $event_post && has_blocks( $event_post->post_content ) ) {
$event_blocks = parse_blocks( get_post( $event_id )->post_content );
// var_dump($event_blocks);
foreach ( $event_blocks as $event_block ) {
if ( 'acf/team-and-author-card-slider' === $event_block['blockName'] ) {
var_dump($event_block);
}
}
}
}
}
}
}
}
}
die();
}