Complete the code to get a custom field value in WordPress.
<?php $value = get_post_meta(get_the_ID(), '[1]', true); ?>
The get_post_meta function requires the custom field key as the second argument to retrieve its value.
Complete the code to display the custom field value inside a paragraph tag.
<p><?php echo [1]; ?></p>To display the custom field value directly, use get_post_meta with the post ID and key, then echo it.
Fix the error in the code to correctly retrieve and display a custom field value.
<?php $value = get_post_meta([1], 'custom_field_key', true); echo $value; ?>
get_the_ID() returns the post ID as a value, which is needed by get_post_meta. the_ID() echoes the ID and cannot be used here.
Fill both blanks to create a custom field display with a fallback message if empty.
<?php $value = get_post_meta(get_the_ID(), [1], true); if ($value [2] '') { echo $value; } else { echo 'No data available'; } ?>
The first blank is the custom field key string. The second blank checks if the value is not equal to an empty string before displaying it.
Fill all three blanks to safely display a custom field value with HTML escaping.
<?php $value = get_post_meta([1], [2], true); echo esc_html([3]); ?>
Use get_the_ID() to get the post ID, the custom field key as a string, and echo the escaped value with esc_html() for security.