Sorting post by custom field and category

If you are on a category page (that is at URL like https://example.com/cateogry/test/ and want to filter your query by “test” category) then you can modify your code to this

global $wp_query;
$query = new WP_Query( 
  array(
    'meta_key' => 'date_event', 
    'orderby' => 'meta_value_num',  
    'order' => 'DESC',
    'tax_query' => array(
        array(
          'taxonomy' => 'advert_category',
          'field'    => 'term_id',
          'terms'    => $wp_query->get_queried_object_id(),
        ),
    )
  )  
);  

This will of course work only if you will run this query once the WP request is parsed and executed, in other words it will work if you run this code after “wp” action.

If you want to add this code in your theme template files then it should work fine.