Querying two taxonomies with tax_query not woking

If you add another tax_query to the args, the last tax_query will replace the previous tax_query.

But anyway, if these are the criteria:

  1. When filtering by type alone, show only resources posts in that type.

  2. When filtering by subject alone, show only resources posts in that subject.

  3. When filtering by type and subject, show only resources posts which are assigned to both type and subject.

Then try this:

$args = array(
    'post_type'      => 'resources',
    'post_status'    => 'publish',
    'posts_per_page' => 8,
);

// Filtering by both 'type' and 'subject'.
if ( $resource_type && $resource_subject ) {
    $args['tax_query'] = array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'type',
            'field'    => 'slug',
            'terms'    => $resource_type,
        ),
        array(
            'taxonomy' => 'subject',
            'field'    => 'slug',
            'terms'    => $resource_subject,
        ),
    );
}
// Filtering by 'type' only.
elseif ( $resource_type && ! $resource_subject ) {
    $args['tax_query'] = array(
        array(
            'taxonomy' => 'type',
            'field'    => 'slug',
            'terms'    => $resource_type,
        ),
    );
}
// Filtering by 'subject' only.
elseif ( $resource_subject ) {
    $args['tax_query'] = array(
        array(
            'taxonomy' => 'subject',
            'field'    => 'slug',
            'terms'    => $resource_subject,
        ),
    );
}

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)