Get taxonomy description based on variable

You have a lot of issues here:

  • You should not be using $_GET variables without sanitizing it. Never ever trust any user inputs and URL parameters. They might contain malicious code which can harm your site. To sanitize and validate a $_GET variable, use the filter_input php function

    $filtered = filter_input( INPUT_GET, 'type', FILTER_SANITIZE_STRING )
    
  • Use the main query and use pre_get_posts to filter the main query accordingly. There is no need to use a custom query as this is an archive page

  • You are trying to get the current term description wrong, you should be using get_term_by to get the term object which will hold the info you need

  • This might be unrelated, but why aren’t you using a taxonomy.php page which will handle all the above as it should. You just need to flush your permalinks and everything should work as it should. But this is something you need to look into in your own time

Lets first sort out the archive page. I have commented the code in order to make it easy to understand. I don’t know how many terms you will pass, but from your code I have taken more that 1. If not, please see the code and adjust accordingly

$filtered = filter_input( INPUT_GET, 'type', FILTER_SANITIZE_STRING );
if ( $filtered  ) {
    /**
     * I don't know if you will be passing more than one term. From your code it seems so
     */
    $types = explode( ' ', $filtered ); 
    foreach ( $types as $type ) {

        /**
         * Get the term object. 
         *
         * I have used the slug here as it seems that you are passing the slug. Adjust as necessary
         *
         * @see get_term_by()
         */
        $term = get_term_by( 'slug', $type, 'product_type' );
        // Make sure that $term has a valid value before outputting anything
        if ( !empty( $term ) || !is_wp_error( $term ) )
            echo $term->description; // Show term description
    }
    /* Replace code above with the following if you are passing just one term
    $term = get_term_by( 'slug', $filtered, 'product_type' ); 
    if ( !empty( $term ) || !is_wp_error( $term ) )
        echo $term->description; // Show term description
    */
    if ( have_posts() ) {
        while( have_posts() ) {
            the_post();

            the_title();
            the_content();
        }
    }

} else {

    // non-filtered page design
    // I don't know what will be displayed here, so I'm keeping the loop and this separate

}

This should sort the archive page. By default, the following is passed by default, so we will not pass them in our action

  • post type

  • offset.

So, lets look at our action. I have again commented the code to make it easy to follow. Please note, the following requires at least PHP 5.4+ due to the short array syntax ([]) being used. For older versions, roll back to old array syntax (array())

add_action( 'pre_get_posts', function ( $q ) 
{
    $filtered = filter_input( INPUT_GET, 'type', FILTER_SANITIZE_STRING );
    if (    !is_admin() // Only target the front end
         && $q->is_main_query() // Only target the main query
         && $q->is_post_type_archive( 'product' ) // Only target product archive page
         && $filtered // If we have a $_GET['type'] variable
    ) {
        if ( isset( $q->get( 'tax_query' ) ) ) //Get current tax query
            $tax_query = []; // Set current tax_query to an empty array

        // Set our new tax_query
        $tax_query = [
            [
                'taxonomy'         => 'product_type',
                'field'            => 'slug'
                'terms'            => explode( ' ', $filtered ),
                'include_children' => false
            ]
        ];
        $q->set( 'tax_query', $tax_query ); // Set new tax_query
        $q->set( 'posts_per_page', -1 ); // Get all posts
        $q->set( 'order', 'DESC' ); // Descending sort order
        $q->set( 'orderby', 'title' ); // Sort by title
    }
});

I hope this is what you need