+ @php
+ global $wpdb;
+ $args = [
+ 'post_type' => 'lc_resource',
+ 'show_date' => false,
+ 'days' => 30,
+ ];
+ $start_date = gmdate('Y-m-d', strtotime("-{$args['days']} days"));
+ $end_date = gmdate('Y-m-d', strtotime('tomorrow midnight'));
+ $sql = $wpdb->prepare("SELECT p.id, SUM(visitors) As visitors, SUM(pageviews) AS pageviews FROM {$wpdb->prefix}koko_analytics_post_stats s JOIN {$wpdb->posts} p ON s.id = p.id WHERE s.date >= %s AND s.date <= %s AND p.post_type = %s AND p.post_status = 'publish' GROUP BY s.id ORDER BY pageviews DESC", [$start_date, $end_date, $args['post_type']]); // @codingStandardsIgnoreLine
+ $results = $wpdb->get_results($sql);
+ $viewed_ids = ( ! empty($results) ) ? wp_list_pluck($results, 'id') : [];
+ $unviewed_ids = get_posts([
+ 'orderby' => 'date',
+ 'order' => 'desc',
+ 'post_type' => 'lc_resource',
+ 'post__not_in' => $viewed_ids,
+ 'posts_per_page' => -1,
+ 'fields' => 'ids'
+ ]);
+ $ids = array_merge($viewed_ids + $unviewed_ids);
+ echo count($viewed_ids);
+ echo count($unviewed_ids);
+ @endphp
{{ sprintf(__('Showing %1$s of %2$s resources for:', 'coop-library'), $found_posts, App::totalPosts('lc_resource')) }}
@if(isset($_GET['s']))
{{ __('Search term', 'coop-library') }}
diff --git a/resources/views/partials/filters.blade.php b/resources/views/partials/filters.blade.php
index 972c7c0..3eb87d6 100644
--- a/resources/views/partials/filters.blade.php
+++ b/resources/views/partials/filters.blade.php
@@ -22,7 +22,7 @@
{{ $label }}