Let current user know pending posts counts using wp_query

As others have already noted in the comments, using "posts_per_page" => 5, is better option than "posts_per_page" => -1, for your query as it will give you the information you need for your conditional check.

Limiting what is queried is also something to consider – as honk31 mentioned. Along 'fields' => 'ids' you can also add the following lines to your query.

  • 'no_found_rows' => true – number of total rows not needed in this
    case
  • 'update_post_meta_cache' => false – meta not needed in this
    case
  • 'update_post_term_cache' => false – terms not needed in this
    case

The $query->have_posts() with wp_reset_postdata(); is also a bit unnecessary as you can just use $query->found_posts or ->post_count directly.

if ( $query->found_posts ) {
  echo $query->found_posts >= 5 ? '5 or more pending posts' : 'Less than 5 pending posts';
} else {
  echo 'Nothing found!';
}