Site icon Hip-Hop Website Design and Development

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

I am creating a search with a form to select specific taxonomies.

The search requires 2 items to be entered, and then has 3 optional terms. All of these are custom taxonomy terms. So once the user hits the search option, I need 2 of the fields in the query to be required, and 3 to be optional. The issue is if I use the ‘relation’=> ‘AND’ it forces all to be required.

Can anyone provide any incite here?

$args = array(
 'post_type' => 'custom',
 'post_parent' => 0,
 'posts_per_page' => 10,
 'orderby' => 'date',
 'order' => 'DESC',
 'post_status'=>'publish',
 'paged' => $paged,
 
 
 //tax
 '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)
    ),

    
    array(
        'taxonomy' => 'optional_1',
        'field' => 'slug',
        'terms' => $optional_1
    ),
    array(
        'taxonomy' => 'optional_2',
        'field' => 'slug',
        'terms' => $optional_2
    ),
    array(
        'taxonomy' => 'optional_3',
        'field' => 'slug',
        'terms' => $optional_3
    )

)