0
0
Wordpressframework~20 mins

Displaying custom field data in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Field Data Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the output of this WordPress code snippet?
Given a post with a custom field 'price' set to '25', what will this code output inside the Loop?
echo get_post_meta(get_the_ID(), 'price', true);
Wordpress
echo get_post_meta(get_the_ID(), 'price', true);
A25
BArray containing '25'
CThe string 'price'
DEmpty string
Attempts:
2 left
💡 Hint
Remember that the third parameter 'true' returns a single value, not an array.
📝 Syntax
intermediate
1:30remaining
Which option correctly retrieves and displays a custom field 'author_name' in WordPress?
Select the code snippet that correctly fetches and echoes the 'author_name' custom field for the current post inside the Loop.
Aecho get_post_meta(get_the_ID(), 'author_name');
Becho get_post_meta('author_name', get_the_ID(), true);
Cecho get_post_meta('author_name');
Decho get_post_meta(get_the_ID(), 'author_name', true);
Attempts:
2 left
💡 Hint
Check the order of parameters for get_post_meta function.
state_output
advanced
2:00remaining
What will be the output of this code when the custom field 'rating' is not set?
Inside the Loop, consider this code:
$rating = get_post_meta(get_the_ID(), 'rating', true);
echo $rating ?: 'No rating available';

What will it output if 'rating' is missing?
Wordpress
$rating = get_post_meta(get_the_ID(), 'rating', true);
echo $rating ?: 'No rating available';
ANo rating available
B0
CEmpty string
DPHP Notice error
Attempts:
2 left
💡 Hint
The ?: operator returns the right side if the left side is empty or false.
🔧 Debug
advanced
2:00remaining
Why does this code not display the custom field value?
This code is inside the Loop:
echo get_post_meta('price', get_the_ID(), true);

Why does it not show the expected price?
Wordpress
echo get_post_meta('price', get_the_ID(), true);
AThe third parameter must be false to get a single value.
BThe parameters are in the wrong order; post ID must be first.
Cget_the_ID() returns null inside the Loop.
DThe meta key 'price' does not exist.
Attempts:
2 left
💡 Hint
Check the order of parameters in get_post_meta function.
🧠 Conceptual
expert
2:30remaining
Which statement about displaying custom field data in WordPress is TRUE?
Choose the correct statement about retrieving and displaying custom field data using get_post_meta.
Aget_post_meta always returns a string regardless of the third parameter.
Bget_post_meta requires the meta key to be the first parameter.
Cget_post_meta returns an array by default unless the third parameter is true.
Dget_post_meta cannot be used inside the Loop.
Attempts:
2 left
💡 Hint
Think about the return type of get_post_meta with and without the third parameter.