0
0
Wordpressframework~10 mins

Displaying custom field data 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 a custom field value in WordPress.

Wordpress
<?php $value = get_post_meta(get_the_ID(), '[1]', true); ?>
Drag options to blanks, or click blank then click option'
A'post_title'
B'custom_field_key'
Cthe_ID()
Dget_post_meta
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function like the_ID() instead of the custom field key.
Passing the wrong argument type for the key.
2fill in blank
medium

Complete the code to display the custom field value inside a paragraph tag.

Wordpress
<p><?php echo [1]; ?></p>
Drag options to blanks, or click blank then click option'
Athe_content()
B$custom_value
Cget_post_meta(get_the_ID(), 'custom_field_key', true)
Dget_the_title()
Attempts:
3 left
💡 Hint
Common Mistakes
Echoing a variable that was not defined.
Using functions that get the post title or content instead.
3fill in blank
hard

Fix the error in the code to correctly retrieve and display a custom field value.

Wordpress
<?php $value = get_post_meta([1], 'custom_field_key', true); echo $value; ?>
Drag options to blanks, or click blank then click option'
Aget_the_ID()
Bthe_ID()
C'custom_field_key'
Dget_post_meta
Attempts:
3 left
💡 Hint
Common Mistakes
Using the_ID() which prints instead of returning the ID.
Passing the custom field key as the first argument.
4fill in blank
hard

Fill both blanks to create a custom field display with a fallback message if empty.

Wordpress
<?php $value = get_post_meta(get_the_ID(), [1], true); if ($value [2] '') { echo $value; } else { echo 'No data available'; } ?>
Drag options to blanks, or click blank then click option'
A'custom_field_key'
B!=
C==
Dempty()
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' which reverses the logic.
Using empty() incorrectly inside the if condition.
5fill in blank
hard

Fill all three blanks to safely display a custom field value with HTML escaping.

Wordpress
<?php $value = get_post_meta([1], [2], true); echo esc_html([3]); ?>
Drag options to blanks, or click blank then click option'
Aget_the_ID()
B'custom_field_key'
C$value
Dthe_ID()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the_ID() which echoes instead of returning the ID.
Not escaping the output which can cause security issues.