Snippets

Rik Kendell Show all results on search.php (WordPress)

Created by Rik Kendell

File functions.php Added

  • Ignore whitespace
  • Hide word diff
+function change_wp_search_size($query) {
+    if ( $query->is_search ) // Make sure it is a search page
+        $query->query_vars['posts_per_page'] = 10; // Change 10 to the number of posts you would like to show. User -1 to show ALL 
+
+    return $query; // Return our modified query variables
+}
+add_filter('pre_get_posts', 'change_wp_search_size'); // Hook our custom function onto the request filter
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.