How to define multi categories posts number

I don’t know if ther’s something similar to posts_per_category or "cat" => array( "5" => array("posts_per_page" => "3"), but you can do it with conditionals, if you form an array with the posts ids. The problem I can see, is that you have to query all posts or set a limit by date for example, but will go like this.

Edit: @Pieter Goosen make me think more about this. He is probably right about the expensiveness of wp_get_post_categories(); but there’s other ways to get the category id, I leave it to you. But giving it a little bit of thought, there’s no need to form an array and then call the post later, if you can print whatever you want directly inside the if statements.

<?php

$args = array ( 'cat' => '1,2,3', 'posts_per_page' => '-1', );

$query = new WP_Query($args);

$cat_1 = 0;
$cat_2 = 0;
$cat_3 = 0;
if($query->have_posts()) {
    while($query->have_posts()) {
        $query->the_post();
        $post_category = wp_get_post_categories(); //Returns an arry with all the categories ids where the post belogs
        $category_posts = [];  //After edit it is only for knowing which posts have been printed yet        
        //Get all posts ids in a general array and count how many you have inserted from each category
        if (in_array( 1, $post_category) && !in_array($category_posts) $cat_1 <= 8) {
            echo "<div class="post-title">";
            the_title();
            echo "</div>";
            $category_posts[] = get_the_ID();
            $cat_1++;
        }

        if (in_array( 2, $post_category) && !in_array($category_posts) $cat_2 <= 10) {               echo "<div class="post-title">";
            the_title();
            echo "</div>";

            $category_posts[] = get_the_ID();
            $cat_2++;
        } 

        if (in_array( 3, $post_category) && !in_array($category_posts) && $cat_3 <= 17 ) {
            echo "<div class="post-title">";
            the_title();
            echo "</div>";
            $category_posts[] = get_the_ID();
            $cat_3++;
        }

    }
}

//$cat_n is for the number of posts you want from each category

Edited: (this is not necessary after edit)

Then you’ll have to loop trough the $category_posts array to get the ids and print whatever you want outside the while loop.

I did this on the fly, so it is probable it has some errors, but this is the general idea.

In this example, if the same posts belogs to two of this categories, it counts for the category with the minor number and not for the other, that’s !in_array($category_posts) for.