add_filter( 'query_vars', function ($vars){
    $vars[] = 'page_id';
    return $vars;
} );
add_action( 'template_redirect', function () {
    if( get_query_var( 'page_id' ) )
    {
        $posts = get_posts([
            'post_type'      => 'page',
            'meta_key'      => 'url',
            'meta_value'    =>  get_query_var( 'page_id' )
        ]);
        if($posts) {
            wp_redirect( get_permalink( $posts[0]->ID ) );
        }
    }} );
add_action( 'init', function (){
    add_rewrite_rule('^(([0-9]{1,2})([a-z]|[A-Z])([0-9]))/?$', 'index.php?page_id=$matches[1]', 'top');
} );
  
  
  
  
  
  <ul class="services-page__contain">
                    <?php
                    $terms_array = array(
                        'taxonomy' => 'service', // you can change it according to your taxonomy
                    );
                    $services_terms = get_terms($terms_array);
                    foreach ($services_terms as $service): ?>
                        <li class="services-page-tile">
                            <?php
                            $queried_object = get_queried_object();
                            $taxonomy = $queried_object->taxonomy;
                            $term_id = $queried_object->term_id;
                            $image = get_field('icons', $taxonomy . '_' . $term_id);
                            echo '<img src="' . $image['url'] . '">'; ?>
                            <img class="services-page-tile__img" src=""
                                 alt="<?php echo $service->name; ?>">
                            <ul>
                                <a class="services-page-tile__description" href="">
                                    <p class="services-page-tile__txt"><?php echo $service->name; ?></p>
                                    <?php
                                    $post_args = array(
                                        'posts_per_page' => -1,
                                        'post_type' => 'service', // you can change it according to your custom post type
                                        'tax_query' => array(
                                            array(
                                                'taxonomy' => 'service', // you can change it according to your taxonomy
                                                'field' => 'term_id', // this can be 'term_id', 'slug' & 'name'
                                                'terms' => $service->term_id,
                                            )
                                        )
                                    );
                                    $myposts = get_posts($post_args); ?>
                                    <?php foreach ($myposts as $post) : setup_postdata($post); ?>
                                        <li class="services-page__link"><?php the_title(); ?></li>
                                    <?php endforeach; ?>
                                    <?php wp_reset_postdata(); ?>
                                </a>
                            </ul>
                        </li>
                    <?php endforeach; // End Term foreach; ?>
  
  $terms_array = array( 
  'taxonomy' => 'services', // you can change it according to your taxonomy
  'parent'   => 0 // If parent => 0 is passed, only top-level terms will be returned
);
$services_terms = get_terms($terms_array); 
foreach($services_terms as $service): ?>
<h4><?php echo $service->name; ?></h4>
<?php 
$post_args = array(
      'posts_per_page' => -1,
      'post_type' => 'service', // you can change it according to your custom post type
      'tax_query' => array(
          array(
              'taxonomy' => 'services', // you can change it according to your taxonomy
              'field' => 'term_id', // this can be 'term_id', 'slug' & 'name'
              'terms' => $service->term_id,
          )
      )
);
$myposts = get_posts($post_args); ?>
<ul>
<?php foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
  <li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  </li>
<?php endforeach; // Term Post foreach ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endforeach; // End Term foreach; ?>        
  
  
  
  
  
  
  
  function wptp_create_post_type() {
    $labels = array(
        'name' => __( 'service' ),
        'singular_name' => __( 'Услуги' ),
        'add_new' => __( 'New Услуги' ),
        'add_new_item' => __( 'Add New Услуги' ),
        'edit_item' => __( 'Edit Услуги' ),
        'new_item' => __( 'New Услуги' ),
        'view_item' => __( 'View Услуги' ),
        'search_items' => __( 'Search Услуги' ),
        'not_found' =>  __( 'No Услуги Found' ),
        'not_found_in_trash' => __( 'No Услуги found in Trash' ),
    );
    $args = array(
        'labels' => $labels,
        'has_archive' => true,
        'public' => true,
        'hierarchical' => false,
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'custom-fields',
            'thumbnail',
            'page-attributes'
        ),
        'taxonomies' => array( 'service'),
    );
    register_post_type( 'service', $args );
}
add_action( 'init', 'wptp_create_post_type' );
// регистрируем таксономию 
function wptp_register_taxonomy() {
    register_taxonomy( 'service', 'service',
        array(
            'labels' => array(
                'name'              => 'service Families',
                'singular_name'     => 'service Family',
                'search_items'      => 'Search service Families',
                'all_items'         => 'All Animal Families',
                'edit_item'         => 'Edit Animal Families',
                'update_item'       => 'Update Animal Family',
                'add_new_item'      => 'Add New Animal Family',
                'new_item_name'     => 'New Animal Family Name',
                'menu_name'         => 'Категория сервисов',
            ),
            'hierarchical' => true,
            'sort' => true,
            'args' => array( 'orderby' => 'term_order' ),
            'rewrite' => array( 'slug' => 'service' ),
            'show_admin_column' => true
        )
    );
}
add_action( 'init', 'wptp_register_taxonomy' );