function mtm_taxonomy_query($archivetype, $display = 3)
{
    $taxonomy = mtm_acf_taxonomy_property($archivetype, 'taxonomy');
    $terms = mtm_acf_taxonomy_property($archivetype, 'name');
    if (get_field('mtm_' . $archivetype . '_archive_taxonomy_number')) {
        $display = get_field('mtm_' . $archivetype . '_archive_taxonomy_number');
    }
    return mtm_page_component_taxonomy_query($taxonomy, $terms, $display);
}
<?php

// Taxonomy Grid
$grid_query = mtm_taxonomy_query('grid');
$taxonomy = mtm_acf_taxonomy_property('grid', 'taxonomy');
?>

<div <?php 
post_class('mtm-component--main');
?>
>
	<?php 
mtm_get_template_part('mtm-content', 'component-page');
?>
	<?php 
if (_get_field('mtm_show_taxonomy_links')) {
    mtm_terms_from_taxonomy_links($taxonomy);
    // output taxonomy
}
?>
</div>

<?php 
if ($grid_query->have_posts()) {
    ?>

	<div class="mtm-component--content mtm-grid--wrapper">
		<div class="gallery-dynamic-row" >

			<?php 
    while ($grid_query->have_posts()) {
<?php

// Manual Grid
$grid_posts = _get_field('mtm_grid_archive_manual');
$taxonomy = mtm_acf_taxonomy_property('manual', 'taxonomy');
?>


<div <?php 
post_class('mtm-component--main');
?>
>
	<h3 class="h1"><?php 
the_title();
edit_post_link('(Edit)', ' • ');
?>
</h3>
	<?php 
mtm_get_template_part('mtm-content', 'component-page');
?>
	<?php 
if (_get_field('mtm_show_taxonomy_links')) {
    mtm_terms_from_taxonomy_links($taxonomy);
    // output taxonomy
}
?>
</div>


<?php 
if ($grid_posts) {
<?php

// Taxonomy List Component
$list_query = mtm_taxonomy_query('list');
$taxonomy = mtm_acf_taxonomy_property('list', 'taxonomy');
$terms = mtm_acf_taxonomy_property('list', 'slug');
$view = _get_field('mtm_show_view_all_link');
?>

<h2 class="h1"><?php 
the_title();
edit_post_link('(Edit)', ' • ');
?>
</h2>
<div <?php 
post_class('mtm-component--main');
?>
>
	<?php 
mtm_get_template_part('mtm-content', 'component-page');
?>
</div>

<?php 
if (_get_field('mtm_show_taxonomy_links')) {
    mtm_terms_from_taxonomy_links($taxonomy);
    // output taxonomy links
}
?>

<?php 
<?php

// Taxonomy Grid Component
global $mtm_grid_row_class;
$grid_query = mtm_taxonomy_query('grid');
$taxonomy = mtm_acf_taxonomy_property('grid', 'taxonomy');
$terms = mtm_acf_taxonomy_property('grid', 'slug');
$view = _get_field('mtm_show_view_all_link');
$mtm_grid_row_class = mtm_output_row_number();
$mtm_grid_module_class = 1;
?>

<h2 class="h1"><?php 
the_title();
edit_post_link('(Edit)', ' • ');
?>
</h2>
<div <?php 
post_class('mtm-component--main');
?>
>
	<?php 
mtm_get_template_part('mtm-content', 'component-page');
?>
</div>

<?php 
if (_get_field('mtm_show_taxonomy_links')) {
    mtm_terms_from_taxonomy_links($taxonomy);
    // output taxonomy links
}
<?php

// Taxonomy List Component
$list_query = mtm_taxonomy_query('list');
$taxonomy = mtm_acf_taxonomy_property('list', 'taxonomy');
?>


<div <?php 
post_class('mtm-component--main');
?>
>
	<h1><?php 
the_title();
edit_post_link('(Edit)', ' • ');
?>
</h1>
	<?php 
mtm_get_template_part('mtm-content', 'component-page');
?>
</div>

<?php 
if (_get_field('mtm_show_taxonomy_links')) {
    mtm_terms_from_taxonomy_links($taxonomy);
    // output taxonomy
}
?>

<?php 
if ($list_query->have_posts()) {