Another query in pre_get_post cause memory issue

Remove the action before you run the internal query, and always verify main query with is_main_query:

function custom_loops($query) {
    if ( $query->is_tax( 'service_photo_location' ) && $query->is_main_query() ){
        remove_action( 'pre_get_posts', 'custom_loops' );
        $ids = get_nearby_partners_by_area(50000, 'service_photo');
        // ...
    }
}
add_action('pre_get_posts', 'custom_loops');

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