Concept Flow - Displaying custom field data
Start: WordPress loads post
Check if custom field exists
Get custom field
Display custom field value
End
WordPress loads a post, checks for a custom field, retrieves it if present, and displays its value.
<?php $value = get_post_meta($post->ID, 'my_custom_field', true); if ($value) { echo $value; } ?>
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Call get_post_meta with post ID and 'my_custom_field' | Returns value or empty string | 'Special offer' |
| 2 | Check if $value is truthy | $value = 'Special offer' | True |
| 3 | Execute echo $value | Outputs 'Special offer' | Displays 'Special offer' on page |
| 4 | End script | No more code | Finished displaying custom field |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| $value | undefined | 'Special offer' | 'Special offer' | 'Special offer' |
Use get_post_meta(postID, 'field_name', true) to get a single custom field value. Check if the value exists before displaying. If true is false, you get an array instead. Echo the value to show it on the page. This is how WordPress displays custom field data safely.