Bird
0
0

Why might this pagination code fail to show correct pages?

medium📝 Debug Q7 of 15
Wordpress - WordPress Query and Database
Why might this pagination code fail to show correct pages?
$paged = get_query_var('paged') ?: 1;
$args = ['posts_per_page' => 5];
$query = new WP_Query($args);
ABecause WP_Query does not support pagination
BBecause posts_per_page is too high
CBecause 'paged' parameter is missing in the query args
DBecause get_query_var('paged') returns null
Step-by-Step Solution
Solution:
  1. Step 1: Check if 'paged' is passed to WP_Query

    The code gets the current page but does not pass 'paged' in the query arguments.
  2. Step 2: Understand effect of missing 'paged'

    Without 'paged', WP_Query always shows the first page results, ignoring pagination.
  3. Final Answer:

    Because 'paged' parameter is missing in the query args -> Option C
  4. Quick Check:

    Missing 'paged' = no pagination [OK]
Quick Trick: Always include 'paged' in WP_Query args for pagination [OK]
Common Mistakes:
  • Not passing 'paged' to WP_Query
  • Assuming posts_per_page controls pagination alone
  • Thinking WP_Query disables pagination

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes