block_core_navigation_get_post_ids example

/** * Get post IDs from a navigation link block instance. * * @param WP_Block $block Instance of a block. * * @return array Array of post IDs. */
function block_core_navigation_from_block_get_post_ids( $block ) {
    $post_ids = array();

    if ( $block->inner_blocks ) {
        $post_ids = block_core_navigation_get_post_ids( $block->inner_blocks );
    }

    if ( 'core/navigation-link' === $block->name || 'core/navigation-submenu' === $block->name ) {
        if ( $block->attributes && isset( $block->attributes['kind'] ) && 'post-type' === $block->attributes['kind'] && isset( $block->attributes['id'] ) ) {
            $post_ids[] = $block->attributes['id'];
        }
    }

    return $post_ids;
}

Home | Imprint | This part of the site doesn't use cookies.