Thanks Jeff. I had a bit of time today to attempt something myself, and came up with the below shortcode function. The coding isn’t up to your standards, but it works ok for my purposes until an official solution:
add_shortcode('sdc_list', 'sdc_download_list');
function sdc_download_list($atts) {
$a = shortcode_atts( [
'cat' => '',
'num' => 5, /* num of downloads to show in list */
'extra' => 'no', /* show select menu for more downloads yes/no */
'select_text' => 'Select more...'
], $atts );
if (empty($cat)) {
return __('No Download Category', 'simple-download-counter');
}
$args = [
'post_type' => 'sdc_download',
'post_status' => 'publish',
'tax_query' => [
[
'taxonomy' => 'sdc_download_category',
'field' => 'slug',
'terms' => $a['cat'],
],
],
'order' => 'DESC',
'orderby' => 'date',
'posts_per_page' => -1,
];
$my_query = new WP_query( $args );
$downloads = $my_query->posts;
$output = '<ul class="sdc_list">';
foreach ( array_slice( $downloads, 0, $a['num'] ) as $item ) {
$url = simple_download_counter_download_url($item->ID);
$hash = get_post_meta($item->ID, 'sdc_download_hash', true);
if ($hash) {
$url = add_query_arg('key', $hash, $url);
}
$output .= '<li><a href="' . esc_url($url) . '">' . esc_html($item->post_title) . '</a></li>';
}
$output .= '</ul>';
if ( $a['extra'] == 'yes' ) {
$output .= '<p><select onchange="if (this.value) window.location.href=this.value">';
$output .= '<option disabled selected>' . $a['select_text'] .'.</option>';
foreach ( array_slice( $downloads, $a['num'], 999 ) as $item ) {
$url = simple_download_counter_download_url($item->ID);
$hash = get_post_meta($item->ID, 'sdc_download_hash', true);
if ($hash) {
$url = add_query_arg('key', $hash, $url);
}
$output .= '<option value="' . esc_url($url) .'">' . esc_html($item->post_title) . '</option>';
}
$output .= '</select></p>';
}
return $output;
}