Bird
0
0

Given this code snippet, what will be the value of $paged if the URL is example.com/page/4/?

medium📝 Predict Output Q4 of 15
Wordpress - WordPress Query and Database
Given this code snippet, what will be the value of $paged if the URL is example.com/page/4/?
$paged = get_query_var('paged') ?: 1;
A1
B4
C0
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Understand get_query_var('paged') behavior

    When visiting example.com/page/4/, WordPress sets the 'paged' query var to 4.
  2. Step 2: Apply null coalescing operator

    The expression get_query_var('paged') ?: 1 returns 4 because 'paged' is set and truthy.
  3. Final Answer:

    4 -> Option B
  4. Quick Check:

    URL page number = $paged value [OK]
Quick Trick: URL page number sets paged value [OK]
Common Mistakes:
  • Assuming paged defaults to 1 always
  • Confusing 0 with null
  • Not understanding get_query_var

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes