Site icon Hip-Hop Website Design and Development

Custom post type pre_get_posts with orderby not work

I have an archive-shops.php page. I want to order the post by shop number. So I add pre_get_posts action in functions.php but it is not working.

In the archive-shops.php

    <?php if( $the_query->have_posts() ): ?>
    <?php
                        while( $the_query->have_posts() ) : $the_query->the_post();
                               //echo content here
                        endwhile;
    endif;
   ?>

In functions.php

add_action( 'pre_get_posts', 'shops_sort_order'); 
function shops_sort_order($query)
{
    if(!is_admin()   && $query->is_main_query() && is_post_type_archive($post_types = 'shops'))
    {
        $query->set( 'orderby', 'shopnum' );
       $query->set( 'order', 'ASC' );
    }
     return $query;
}