Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Pass the ID of the post that owns the field. The Loop is not required for metadata retrieval: WordPress core accepts a post ID directly, and ACF or Secure Custom Fields (SCF) accepts the target ID as its second argument.
$post_id = 123; // The post that owns the field
$value = get_post_meta( $post_id, 'field_name', true );
echo esc_html( $value );
Use the ID for the content item whose value you want—not whichever post happens to be in the global $post at that moment.
Use the owning post’s ID
Outside the main Loop, template context may refer to the page being rendered, a secondary query, or no post at all. A custom field belongs to a specific post, page, or custom-post-type item, so retrieve it with that item’s ID.
Known post or page
$post_id = 123;
$value = get_post_meta( $post_id, 'subtitle', true );
if ( $value !== '' ) {
echo esc_html( $value );
}
Replace 123 with the real numeric ID and subtitle with the exact saved meta key. A WP_Post object can also supply the ID:
#1 Best Overall
- Ergonomic Posture Correction: Designed to elevate your laptop to the perfect eye level, this adjustable laptop stand significantly reduces neck, shoulder, and spinal fatigue. Transform your desk into a healthier workstation, ideal for long hours of typing, Zoom meetings, or gaming.
- Unshakable Dual-Rod Stability: Unlike single-hinge models, our stand features a highly engineered dual-support rod mechanism. It perfectly distributes weight to ensure a 100% wobble-free typing experience, safely supporting heavy-duty devices up to 22 lbs (10kg).
- Advanced Thermal Cooling Panel: Maximize your device's performance. The unique geometric heat-vent design on the upper panel provides superior airflow compared to standard solid stands. This continuous heat dissipation prevents your laptop from thermal throttling and hardware damage during intensive tasks.
- Universal 10-16” Compatibility: A versatile computer riser that seamlessly fits all 10 to 16-inch laptops. Broadly compatible with MacBook Pro/Air, Dell XPS, HP, Lenovo, ASUS, Chromebook, and large gaming laptops. The anti-slip silicone pads firmly grip your device and protect it from scratches.
- Foldable, Portable & Ready to Go: Maximize your productivity anywhere. The dual-foldable design allows the stand to collapse completely flat in seconds. Easily slip it into your backpack or briefcase, making it the ultimate portable office accessory for business trips, cafes, or hybrid work setups.
$post_id = $post_object->ID;
$value = get_post_meta( $post_id, 'subtitle', true );
Current singular page
When the field belongs to the singular post or page currently being viewed, obtain that queried object’s ID and pass it explicitly:
$post_id = get_queried_object_id();
$value = get_post_meta( $post_id, 'subtitle', true );
if ( $value !== '' ) {
echo esc_html( $value );
}
Use this only when the request is actually for the content item that owns the field. A component that displays a different post must use that other post’s ID.
A different post in a component
For a featured article, reusable block, author card, or other component, pass the ID supplied by the component’s data rather than relying on global context:
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →function render_featured_subtitle( $featured_post_id ) {
$value = get_post_meta( $featured_post_id, 'subtitle', true );
if ( $value !== '' ) {
echo esc_html( $value );
}
}
Read core WordPress metadata with get_post_meta()
The core signature is get_post_meta( int $post_id, string $key = '', bool $single = false ). The official reference documents the parameters and return behavior at get_post_meta() – Function.
One scalar value
Set the third argument to true when you want one value:
Rank #2
- Broad Compatibility: Besign LS03 Laptop Mount is compatible with all laptops from 10''-15.6'', such as Air 13, Pro 13 / 15 / 2018 / 2017 / 2016, Lenovo ThinkPad, Dell, HP, ASUS, Chromebook, and other notebooks.
- Ergonomic Design: This LS03 Laptop Stand could elevate your laptop by 6’’ to a perfect viewing level, help you improve your posture and reduce neck and shoulder pain. This laptop stand is super easy to detach and assemble.
- Stable And Protective: This laptop stand is made of premium Aluminum alloy, it is sturdy, support up to 8.8 lbs(4kg), no worry any wobble at all; the rubber on the holder hands sticks tightly, ensure your laptop stable on the stand and prevent any scratches.
- Keep Laptop Cool: the open aluminum design provides good ventilation and airflow to prevent your laptop from overheating. It folds flat if you need to store it, create extra space on your desk and keep your desk clean and organized.
- Easy to Use: thanks to the detachable design, you could assemble it very easily it 3 steps.
$value = get_post_meta( $post_id, 'subtitle', true );
For non-serialized metadata, WordPress returns strings, including numeric-looking values. Do not assume a value such as 42 is a PHP integer without converting and validating it for your use case.
Multiple values
Leave $single as false when the key may have several saved values:
Recommended Free Tools
$values = get_post_meta( $post_id, 'related_link', false );
foreach ( $values as $value ) {
echo '<li>' . esc_html( $value ) . '</li>';
}
A missing key and an intentionally stored empty value can produce different application requirements. If your logic must distinguish “no key exists” from “key exists but is empty,” check key existence separately instead of treating a non-empty string as the only state.
Escape for the output context
Metadata is not automatically safe for every output context. Escape plain text with esc_html(); use context-specific functions for attributes and URLs:
$label = get_post_meta( $post_id, 'button_label', true );
$url = get_post_meta( $post_id, 'button_url', true );
if ( $label !== '' && $url !== '' ) {
printf(
'<a href="%s">%s</a>',
esc_url( $url ),
esc_html( $label )
);
}
Do not echo untrusted metadata raw. If a field is intended to contain permitted markup, sanitize and render it according to that field’s documented format rather than applying text escaping blindly.
Rank #3
- ✔️[Foldabe & Protable] - Foldable laptop stand for desk & Protable computer stand, It combines the advantages of market brackets, convenient travel laptop stand. Easy to use. Suitable for working at home, office and outdoor, improve comfort.
- ✔️[360°Rotation] - The computer stand with 360° rotating base, 360° rotation connected with the base is more flexible, the computer stand allows you to rotate the laptop to any angle.
- ✔️[Stable & Durable] - The Computer stand is made of one-piece fiber metal material, which is more durable and stable than ordinary aluminum alloy computer stands. The upgraded rotating base makes the stand performance more stable, and the non-slip silicone protects the laptop from sliding.Only supports laptops up to 16 inches.
- ✔️[Ergonmic Desing] - You can freely adjust the height and angle of the laptop stand to keep it at eye level, which helps to reduce the pressure on your body while working. Whether sitting or standing, there is a comfortable angle.
- ✔️[Wide Compatibility] - Our laptop stand is compatible with all laptops from 10-16 inches, such as MacBook Air/Pro, Google PixelBook, Dell XPS, HP, ASUS, Lenovo ThinkPad, Acer, Chromebook and Microsoft Surface, etc. It is an ideal companion for computer workers.
Use ACF or Secure Custom Fields when the field is managed by that plugin
ACF and SCF provide get_field(). Pass the field’s actual name or key and the target post ID:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
$value = get_field( 'subtitle', $post_id );
if ( $value !== null && $value !== false && $value !== '' ) {
echo esc_html( $value );
}
SCF documents this template API in its API Template Global Functions handbook. The plugin is optional; it is not required for ordinary WordPress post metadata.
Account for formatted return values
get_field() can format a value according to the field configuration. A text field may return a string, while an image, link, relationship, repeater, or group field can return an array or structured value. Inspect the configured return type before rendering:
$image = get_field( 'hero_image', $post_id );
if ( is_array( $image ) && ! empty( $image['url'] ) ) {
printf(
'<img src="%s" alt="%s">',
esc_url( $image['url'] ),
esc_attr( $image['alt'] ?? '' )
);
}
Use the escaping and markup appropriate to the returned type. Applying esc_html() to an array will not produce a useful image or link.
Display fields while rendering a secondary query
If you are displaying several queried posts, a loop over that query is appropriate. Use each result’s ID for its field:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #4
- 【Adjustable & Ergonomic】:This laptop stand can be adjusted to a comfortable height and angle according to your actual needs, letting you fix posture and reduce your neck fatigue, back pain and eye strain. Very comfortable for working in home, office and outdoor.
- 【Sturdy & Protective】 :Made of sturdy metal, it can support up to 17.6 lbs (8kg) weight on top; With 2 rubber mats on the hook and anti-skid silicone pads on top & bottom, it can secure your laptop in place and maximum protect your device from scratches and sliding. Moreover, smooth edges will never hurt your hands.
- 【Heat Dissipation】 :The top of the laptop stand is designed with multiple ventilation holes. The open design offers greater ventilation and more airflow to cool your laptop during operation other than it just lays flat on the table.
- 【Portable & Foldable】:The foldable design allows you to easily slip it in your backpack. Ideal for people who travel for business a lot.
- 【Broad Compatibility】:Our desktop book stand is compatible with all laptops from 10-15.6 inches, such as MacBook Air/ Pro, Google Pixelbook, Dell XPS, HP, ASUS, Lenovo ThinkPad, Acer, Chromebook and Microsoft Surface, etc.Be your ideal companion in Home, Office & Outdoor.
$related = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 3,
) );
if ( $related->have_posts() ) {
while ( $related->have_posts() ) {
$related->the_post();
$value = get_post_meta( get_the_ID(), 'subtitle', true );
if ( $value !== '' ) {
echo '<p>' . esc_html( $value ) . '</p>';
}
}
}
wp_reset_postdata();
the_post() changes the global post context used by template tags. Call wp_reset_postdata() after the secondary loop to restore the main query’s post. See the WP_Query class reference for query behavior and the Theme Handbook’s Loop guide for context handling.
Choose the appropriate API or workflow
| Situation | Use | What you pass | Important detail |
|---|---|---|---|
| Direct WordPress metadata | get_post_meta() |
Post ID, exact key, and true or false |
Returns one value or an array; values are commonly strings. |
| ACF/SCF-managed field | get_field() |
Field name or key and target post ID | Formatting settings can return arrays or other structured data. |
| Several posts from a custom query | Secondary WP_Query loop |
Each result’s ID during iteration | Restore the original context with wp_reset_postdata(). |
Why the field is empty outside the Loop
The wrong post ID was passed
The most common cause is retrieving the field from the page currently rendering instead of the post that owns the value. Log or inspect the ID and compare it with the editor screen’s post ID.
The key or field name does not match
Core metadata requires the exact saved meta key. ACF/SCF requires the configured field name or key, not necessarily the human-readable field label.
The field has no saved value
Check the target post in the editor and account for intentionally blank values. A conditional such as $value !== '' prevents an empty element from being printed.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsThe return type is not plain text
An image, relationship, repeater, or group may be an array or object. Inspect it before output and render its documented properties.
Best Value
- ✅【Adjustable & Ergonomic】:This laptop stand can be adjusted to a comfortable height and angle according to your actual needs, letting you fix posture and reduce your neck fatigue, back pain and eye strain. Very comfortable for working in home, office and outdoor.
- ✅【Sturdy & Protective】 :Made of sturdy metal, it can support up to 17.6 lbs (8kg) weight on top; With 2 rubber mats on the hook and anti-skid silicone pads on top & bottom, it can secure your laptop in place and maximum protect your device from scratches and sliding. Moreover, smooth edges will never hurt your hands.
- ✅【Heat Dissipation】 :The top of the laptop stand is designed with multiple ventilation holes. The open design offers greater ventilation and more airflow to cool your laptop during operation other than it just lays flat on the table.
- ✅【Portable & Foldable】:The foldable design allows you to easily slip it in your backpack. Ideal for people who travel for business a lot.
- ✅【Broad Compatibility】:Our laptop holder is compatible with all laptops from 10-17.3 inches, such as MacBook Air/ Pro, Google Pixelbook, Dell XPS, HP, ASUS, Lenovo ThinkPad, Acer, Chromebook and Microsoft Surface, etc.Be your ideal companion in Home, Office & Outdoor.
A secondary query left global state changed
If a later template tag shows data from the wrong post, ensure every custom loop that calls the_post() ends with wp_reset_postdata().
Practical checklist
- Identify the post, page, or custom-post-type item that owns the field.
- Pass that item’s explicit ID to the getter.
- Use the exact core meta key or ACF/SCF field name/key.
- Choose a single value or multiple values deliberately.
- Inspect plugin field return types before rendering.
- Escape for HTML text, attributes, URLs, or other output contexts.
- Reset post data after a secondary
WP_Queryloop.
WordPress’s documentation describes custom fields as values displayed through a template tag that customizes the theme; the relevant guide is Assign custom fields.
Frequently Asked Questions
Can I display an ACF field from another post?
Yes. Call get_field( 'field_name', $other_post_id ) and pass the ID of the post that owns the field.
Do I need to be inside The Loop to use custom fields?
No. get_post_meta() and get_field() accept an explicit post ID, so they can run outside the main Loop.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

