Modal opens all post IDs

So your script is doing exactly what you have told it to do.

Here you are passing the element to the function, but you never use it, instead you just query all elements with a class and add another class.

function moreinfoModal(field) {
    console.log(field.id);
    $('.moreinfo-modal').toggleClass('open');
}

What you should do is only add the class to the element the buttin is targeting:

function moreinfoModal(field) {
    // Get the button target.
    var target = field.getAttribute('data-target')
    // Add class to target.
    $(target).addClass('open');
}

And when you need to close the model window. You can just look for only models that are open. As you aren’t passing an element in to get the id from.

function closeMoreInfoModal() {
    // Close all windows because you we dont have the open elements id.
    $('.moreinfo-modal.open').removeClass('open');
}