How to display posts in hyperlink with nested slugs?

Important question

How do i create nesting slugs like this —

Here – the slug displaypage is the page slug, and family1 and family2 are the name of the groups which i have stored in my custom table..
members is the tab which displays the number of users in each group
Please answer this question

Solutions Collecting From Web of "How to display posts in hyperlink with nested slugs?"

This can be achieved by adding rewrite rules.

First, add the query vars that will store the custom values in our rules:

function wpd_family_query_var( $query_vars ) {
    $query_vars[] = 'wpd_family';
    $query_vars[] = 'wpd_members';
    return $query_vars;
add_filter( 'query_vars', 'wpd_family_query_var' );

Next, add the rules to capture both displaypage/family/ and displaypage/family/members/ requests:

function wpd_add_family_rewrite_rules() {
add_action( 'init', 'wpd_add_family_rewrite_rules' );

Don’t forget, you must flush rewrite rules after changing them.

You will then be able to access the values of your query vars anywhere after the parse_query action with get_query_var():

if( $family = get_query_var( 'wpd_family' ) ){
    echo 'family: ' . $family;

if( $members = get_query_var( 'wpd_members' ) ){
    echo 'members: ' . $members;