Created
February 8, 2024 01:07
-
-
Save digisavvy/42fcd1a4fb1def2f3fa4487db78f68bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
You did a very fantastic job 😊
Keep up the good work. I wish you all the best.