WP_Query for CPT with filter by another WP_Query

You’re correct in your approach. If you post your code will be better, but something like this:

$args = array(
    'post_type' => 'project',
    'tax_query' => array(
        array(
            'taxonomy' => 'region',
            'field'    => 'slug',
            'terms'    => $region, //set your region
        ),
    ),
);
$the_query = new WP_Query( $args );

// The Loop of Projects by Region
if ( $the_query->have_posts() ) {

    $projectsid = array();
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        $projectsid[] = get_the_ID();
    }

    $args = array(
        'post_type' => 'unit',
        'meta_query' => array(
            array(
                'key'       => $keyname, //set the key name which store ID
                'value'     => $projectsid,
                'compare'   => 'IN',
                'type'      => 'NUMERIC'
            ),
        ),
    );
    $the_query = new WP_Query( $args );

    // The Loop of units in project per region
    if ( $the_query->have_posts() ) {

        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            //do something

        }

    } else {

        //No units for projects in this region

    }

} else {

    //No projects in this region

}

wp_reset_query();

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