Add the post id to your link that you are opening the modal with (this will be used to pass the post id to the ajax function):
<li class="slide col25">
<a href="#modal1" class="easy-modal-open" data-post-id="<?= get_the_ID(); ?>">
//img and h4
</a>
</li>
use wp_localize_script to pass the ajaxurl to your jquery:
wp_localize_script( 'my_modal', 'my_modal_localize', array(
ajaxurl => admin_url('admin-ajax.php')
) );
add a function to query the correct company to your functions.php (something like you have above):
add_action( 'wp_ajax_custom_function', 'get_company_modal' );
add_action( 'wp_ajax_nopriv_custom_function', 'get_company_modal' );
function get_company_modal() {
$args = array(
p => $_POST['post_id'], //this is the post id passed via jquery.post()
);
$query = new WP_Query( $args );
$result = array();
if( $query->have_posts() ) {
while( $query->have_posts() ) {
$query->the_post();
// get all your custom fields here and add them to the $result array
$result[ $custom_field_key ] = $custom_field_value;
}
}
echo json_encode( $result );
die();
}
and then add the call to the click event in your jquery using .post()
$('.easy-modal-open').click(function(e) {
var data = {
action: 'custom_function', //see the add_action part above
post_id: $(this).data('post-id'), //this is the post id from the a data attribute
}
$.post( my_modal_localize.ajaxurl, data, function(response) {
var customFields = $.parseJSON(response);
// add the custom fields to your output via e.g. append()
}
// and THEN open the modal
var target = $(this).attr('href');
$(target).trigger('openModal');
e.preventDefault();
});
maybe you'll need to add a $.when().then() but that depends on the situation.
So this is only an example and one way of achieving what you want. You will of course edit it to suit your situation.