Wrap your WP_Query object in a function so you don’t have to change all the query $args.
The function will pass parameters for custom field value and order by custom field value.
Here how you can do it:
<?php
function custom_query($divided_cf_val=array(), $order_by_cf_val) {
?>
<div id="listings">
<?php
$args = array(
'post_type' => 'listing',
'post_status' => 'publish',
'posts_per_page' => '96',
'meta_key' => 'price_value',
'orderby' => $order_by_cf_val,
'order' => 'ASC',
'meta_query' => $divided_cf_val
);
$custom = new WP_Query( $args ); ?>
<h3 class="bar">Category 1 (<?php echo $custom -> found_posts; ?>)</h3>
<?php $margincounter = 1; ?>
<?php if ($custom->have_posts()) : while ($custom->have_posts()) : $custom->the_post(); ?>
<?php include get_template_directory() . '/includes/listings_grid.php'; ?>n in y
<?php endwhile; else: ?>
<?php endif; wp_reset_query(); ?>
</div>
<?php
}
?>
And call this function in your template like this:
<?php
$meta_field1 = array(
array(
'key' => 'category_value',
'value' => 'category 1',
),
array(
'key' => 'sold_value',
'value' => 'No'
)
);
$meta_field2 = array(
array(
'key' => 'category_value',
'value' => 'category 2',
),
array(
'key' => 'sold_value',
'value' => 'Yes'
)
);
$meta_field3 = array(
array(
'key' => 'category_value',
'value' => 'category 3',
),
array(
'key' => 'sold_value',
'value' => 'Maybe'
)
);
custom_query($meta_field1, $order_by_cf_val);
custom_query($meta_field2, $order_by_cf_val);
custom_query($meta_field3, $order_by_cf_val);
custom_query($meta_field4, $order_by_cf_val);
?>
and so on…