Skip to content

Commit

Permalink
fix issue with most popular posts not working with pages due to WP_Qu…
Browse files Browse the repository at this point in the history
…ery default arguments
  • Loading branch information
dannyvankooten committed Oct 19, 2023
1 parent ec27ec0 commit 925b36e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ function get_most_viewed_posts(array $args = array()): array
'post__in' => $post_ids,
// indicates that we want to use the order of our $post_ids array
'orderby' => 'post__in',
// excludes SQL_CALC_FOUND_ROWS from the query, tiny performance gain

// By default, WP_Query only returns "post" types
// Without this argument, this function would not return any page types
'post_type' => 'any',
// Prevent sticky post from always being included
'ignore_sticky_posts' => true,
// Excludes SQL_CALC_FOUND_ROWS from the query (tiny performance gain)
'no_found_rows' => true,
)
);
Expand Down

0 comments on commit 925b36e

Please sign in to comment.