add_filter( 'next_posts_link_attributes',
$filter_link_attributes );
// Take into account if we have set a bigger `max page`
// than what the query has.
global $wp_query;
if ( $max_page >
$wp_query->max_num_pages
) { $max_page =
$wp_query->max_num_pages;
} $content =
get_next_posts_link( $label,
$max_page );
remove_filter( 'next_posts_link_attributes',
$filter_link_attributes );
} elseif ( !
$max_page ||
$max_page >
$page ) { $custom_query =
new WP_Query( build_query_vars_from_query_block( $block,
$page ) );
$custom_query_max_pages =
(int) $custom_query->max_num_pages;
if ( $custom_query_max_pages &&
$custom_query_max_pages !==
$page ) { $content =
sprintf( '<a href="%1$s" %2$s>%3$s</a>',
esc_url( add_query_arg( $page_key,
$page + 1
) ),
$wrapper_attributes,
$label );
} wp_reset_postdata(); // Restore original Post Data.
}