The easiest way to optimize this query would be to add 'fields' => 'ids'
to the arguments. This way only ids of posts will be retrieved from DB (and usually that’s a big change).
$args = [
'numberposts' => -1,
'post_type' => 'jobs',
's' => 'developer',
'tax_query' => ['taxonomy' => 'IT', 'field' => 'slug'],
'fields' => 'ids'
];
$posts = get_posts($args);
$count = count($posts);
On the other hand you can use WP_Query
instead of get_posts
. This way you can set posts_per_page
to 1, so only one ID will be retrieved and use found_posts
field of WP_Query to get the total number of posts matching your criteria.
$args = [
'posts_per_page' => 1,
'post_type' => 'jobs',
's' => 'developer',
'tax_query' => ['taxonomy' => 'IT', 'field' => 'slug'],
'fields' => 'ids'
];
$query = new WP_Query($args);
$count = $query->found_posts;