Finding post ID dynamically on click

What you’re looking to accomplish isn’t really pagination. That threw me off initially. You’re building a navigation that will be site-wide.

If that’s the case, you can either capture the ID from the url (this is not very performant) or add the ID to the markup.

This example shows you how to add the ID as a data attribute on the menu’s anchor tag:

function my_nav_menu_link_attributes( $atts, $item, $args ) {
        // Replace with the theme location name for your menu.
    if ( 'menu-1' === $args->theme_location ) {
        // This works for posts or pages. Add extra custom post types to include.
        if ( isset( $item->object_id ) && ( 'post' === $item->object || 'page' === $item->object ) ) {
            $atts['data-post-id'] = $item->object_id;
        }
    }
    return $atts;
}
add_filter( 'nav_menu_link_attributes', 'my_nav_menu_link_attributes', 10, 3 );

If you use this, you can grab the data attribute data-post-id for each link that’s clicked.

The markup will look something like this:

<li id="menu-item-52" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-52"><a href="https://wordpress.stackexchange.com/sample-page/" data-post-id="2">Sample Page</a></li>