Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save digisavvy/42fcd1a4fb1def2f3fa4487db78f68bd to your computer and use it in GitHub Desktop.
Save digisavvy/42fcd1a4fb1def2f3fa4487db78f68bd to your computer and use it in GitHub Desktop.
// Start of Selection
// Initialize the arguments for the WP query to fetch various post types
$args = array(
'post_type' => ['post', 'session', 'resource', 'video'], // Define post types to query
'posts_per_page' => -1, // Set to '-1' to fetch all posts. Replace with a specific number if needed
'order' => 'DESC', // Order by descending to get the most recent or viewed first
// You can add more arguments here as per your query requirements
);
// Retrieve the most viewed posts using a function provided by the Post Views Counter plugin
$most_viewed_posts = pvc_get_most_viewed_posts($args);
// Map the retrieved posts to an array of their IDs for further use
$post_ids = array_map(function($post) {
return $post->ID; // Return the ID of each post
}, $most_viewed_posts);
// Construct the arguments for the Bricks query loop
// This will ensure that only the most viewed posts are included in the loop
// and that they are ordered by the number of views they have received
return array(
'post_type' => ['post', 'session', 'resource', 'video'], // Specify the same post types as above
'posts_per_page' => 9, // Limit the number of posts to display. Adjust as needed
'post__in' => $post_ids, // Include only the posts that are most viewed
'orderby' => 'post__in', // Maintain the order based on the most viewed posts
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment