Custom WP Query: force entry for some taxonomy and have others optional

It’s hard to say exactly what your query is trying to accomplish, but I’ll provide the two setups that come to my mind, and hope they help you out.

You could setup your query arguments with the two required taxonomies and terms being searched for like:

$args = array(
    'post_type' => 'custom',
    'post_parent' => 0,
    'posts_per_page' => 10,
    'orderby' => 'date',
    'order' => 'DESC',
    'post_status'=>'publish',
    'paged' => $paged,
 
    //taxonomy query default
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'required_1',
            'field' => 'slug',
            'terms' => array($required_1)
        ),
        array(
            'taxonomy' => 'required_2',
            'field' => 'slug',
            'terms' => array($required_2)
        ),
    ),
);

Then if you also want to have an optional taxonomy and term being searched with the first two required terms, you could dynamically add another query array to your $args['tax_query'] array depending on if the optional taxonomy terms are present. So the tax query would check if required 1 matches AND if required 2 matches, and if it’s present, then check if optional 1 matches AND check if optional 2 matches, etc:

if( !empty($optional_1) ) {
    $optional_1_array = [
        'taxonomy' => 'optional_1',
        'field' => 'slug',
        'terms' => array($optional_1)
    ];

    $args['tax_query'][] = $optional_1_array;
}

You can rinse and repeat for other optional terms that may be present, or create a loop for adding those optional terms to the query if you don’t know how many there will be maybe.

Another query that came to mind might be to dynamically add optional terms to arrays that uses the relation OR, and are nested in the original taxonomy query. So the first two taxonomy terms would use AND, and then the optional terms would use OR between them. In other words the query would check if required 1 matches AND if required 2 matches AND if any of optional 1 OR optional 2 OR optional 3 matches.

That could look something like this, though this is rather verbose code that could likely be cleaned up better:

if( !empty($optional_1) || !empty($optional_2) || !empty($optional_3) ){
    // if any of the optional terms have been sent by user, setup new array with relation OR to start
    $optional_array = [
        'relation' => 'OR',
    ];
    // then if $optional_1 was sent, store an appropriate array for that query nested inside of $optional_array
    if( !empty($optional_1) ) {
        $optional_1_array = [
            'taxonomy' => 'optional_1',
            'field' => 'slug',
            'terms' => array($optional_1)
        ];
        $optional_array[] = $optional_1_array;
    }
    
    $args['tax_query'][] = $optional_array;
}