How to edit this code to get the categories in achieve page?

first thing that i notice, is that you use some obscure WP loop markup

foreach( $myposts as $post ) : setup_postdata($post); 

Please loop with standard markup an WP_Query class

<?php $query = new WP_Query( $args ); ?>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>

https://codex.wordpress.org/The_Loop

Next thing, that is problem in your code is, that you don’t even try to get posts from some category. If your taxonomy is standard category, then you will get it with standard ‘cat’ parameter:

$query = new WP_Query( array( 'cat' => 4 ) );

https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

If it’s custom taxonomy, then you need to call it with taxonomy parameter:

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        array(
            'taxonomy' => 'people',
            'field'    => 'slug',
            'terms'    => 'bob',
        ),
    ),
);
$query = new WP_Query( $args );

https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters