I would start by creating an array to put your posts into, to create a counting system of some kind. Dump your list item output into that array, count it, and use the remaining count to call your second query.
<?php
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
$sticky = get_option('sticky_posts');
// Moved the base arguments into one array
$base_args = array(
'posts_per_page' => 5, // Changed to 5, because that's the amount you need
'post_type' => MYCPT_POST_TYPE,
'orderby' => 'rand'
'post__in' => $sticky,
);
// Merge your base arguments and cat only arguments
$args_cat_only = array_merge( $base_args, array (
'my_cat' => $term->slug,
) );
$cat_only_query = new WP_Query( $args_cat_only );
if ( $cat_only_query->have_posts() ) {
while ( $cat_only_query->have_posts() ) { $cat_only_query->the_post();
// Start an Output Buffer
ob_start();
?>
<li>
// items from category only
</li>
<?php
// Dump output into list item array
$list_items[] = ob_get_clean();
}
wp_reset_postdata();
}
if ( count( $list_items ) < 5 ) {
// Find out how many posts you need
$post_need = 5 - count( $list_items );
// Change base args posts_per_page to only call the amount of posts you need
$base_args['posts_per_page'] = $post_need;
// Run the new query based on base arguments
$fill_in_query = new WP_Query( $base_args );
if ( $fill_in_query->have_posts() ) {
while ( $fill_in_query->have_posts() ) { $fill_in_query->the_post();
// Start an Output Buffer
ob_start();
?>
<li>
// items from category only
</li>
<?php
// Dump output into list item array
$list_items[] = ob_get_clean();
}
wp_reset_postdata();
}
}
?>
<div class="slider">
<ul>
<?php echo implode( '', $list_items ); // Print your list items ?>
</ul>
</div>
The only problem now is that your random pull in your second query could technically pull a random one from the first query.
I didn’t test any of this code, please let me know if you have any questions.