0
0
Wordpressframework~10 mins

Query parameters in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the value of a query parameter named 'page'.

Wordpress
$page = $_GET[[1]];
Drag options to blanks, or click blank then click option'
A'user'
B'post'
C'page'
D'id'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use quotes around the parameter name.
Using $_POST instead of $_GET for query parameters.
2fill in blank
medium

Complete the code to check if the 'category' query parameter exists.

Wordpress
if (isset($_GET[[1]])) {
    // do something
}
Drag options to blanks, or click blank then click option'
A'date'
B'category'
C'author'
D'tag'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking $_POST instead of $_GET.
Using the wrong parameter name.
3fill in blank
hard

Fix the error in the code to safely get the 'author' query parameter or set it to 'guest' if missing.

Wordpress
$author = $_GET[[1]] ?? 'guest';
Drag options to blanks, or click blank then click option'
A'user'
B'admin'
C'name'
D'author'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong parameter name.
Not using quotes around the parameter name.
4fill in blank
hard

Fill both blanks to create a query that gets posts filtered by 'tag' and ordered by 'date'.

Wordpress
$args = array(
    'tag' => $_GET[[1]],
    'orderby' => [2]
);
Drag options to blanks, or click blank then click option'
A'tag'
B'category'
C'date'
D'title'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'tag' and 'category' keys.
Using a variable instead of a string for 'orderby'.
5fill in blank
hard

Fill all three blanks to build a WP_Query args array filtering by 'author', limiting posts to 5, and ordering by 'title'.

Wordpress
$args = array(
    'author_name' => $_GET[[1]],
    'posts_per_page' => [2],
    'orderby' => [3]
);
Drag options to blanks, or click blank then click option'
A'author'
B5
C'title'
D'category'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'author' without quotes in the first blank.
Using a string instead of a number for posts_per_page.
Using a variable instead of a string for orderby.