Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Displaying Custom Post Meta

To modify the content of a post, you can use the_content filter. You (probably) only want to add the post meta to the main query. If not, you can skip the is_main_query() conditional. Then you can just get the post meta and format it how you see fit and append it to the content.

//* Add filter to the_content if we're in the main query
add_action( 'the_post', 'wpse_261935_the_post' );
function wpse_261935_the_post( $post ) {
  if( is_main_query() ) {
    add_filter( 'the_content', 'wpse_261935_the_content' );
  }
}
function wpse_261935_the_content( $content ) {
  //* Make sure to add and remove filter for each post
  //* to make sure it's in the main query
  remove_filter( 'the_content', 'wpse_261935_the_content' );

  $wpse_261935_meta = get_post_meta( get_post()->ID, '_wpse_261935_post_meta_key', true );
  $wpse_261935_content = wpse_261935_format_post_meta( $wpse_261935_meta );

  return $wpse_261935_content . $content;
}
function wpse_261935_format_post_meta( $post_meta ) {
  //* Format the post meta however you'd like
  return $html;
}

Related Posts:

  1. Save metabox with multiple checkbox array
  2. Ordering posts by metadata
  3. Saving value of a selection option in comment form as comment meta
  4. Run Shortcode of post’s custom field in functions.php / Plugin
  5. Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
  6. Any way to update_post_meta with html content? It gets stripped and becomes empty
  7. How can I add an image upload field directly to a custom write panel?
  8. Post meta vs separate database tables
  9. How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?
  10. How to validate custom fields in custom post type?
  11. How to add tab which is visible only in admin side of product in woocommerce? [closed]
  12. Creating custom field with drop down on new post page
  13. Retrieving custom fields with $wpdb->get_results
  14. How to create Image gallery Metabox in wordpress [closed]
  15. Utilize TinyMCE hyperlink chooser outside of TinyMCE
  16. How to enable users to down-vote in this simple voting counter (that uses the post meta)?
  17. anything like add_meta_box for categories?
  18. template_redirect for single posts w/ custom fields
  19. How can I free up the memory used by update_post_meta?
  20. Is there a way to list tags order by post_meta field
  21. Support auto-save and revisions for custom fields
  22. Best choice of options/settings framework for plugin/theme development
  23. Plugin development: get_post_meta is not working [closed]
  24. Act on user meta updated, but only once
  25. How to check if Woocommerce Order number equals to post ID?
  26. Adding set of custom fields to WordPress Post in Dashboard
  27. update post meta for checkbox in the admin when inserted in the front-end
  28. 403 Error when text is pasted in Custom Metabox Textarea
  29. get_posts() not working when accessing with a custom user role
  30. Custom Taxonomy to dropdown box on adminside wordpress
  31. Create & Save multiple Meta-boxes
  32. Add a Save Button to Custom Meta Box [duplicate]
  33. Plugin with action ‘save_post’ needs to press publish twice on order to publish
  34. Strange issue saving custom field data for a WooCommerce order
  35. Woocommerce – Convert Delivery method into a custom field
  36. How to get Metabox custom field to show checked if value is updated using post meta query?
  37. How do I update a field of a meta box?
  38. Input value from metabox is not found in $_POST after post save
  39. Doubts about the use of metadata and how this can affect performance on WordPress
  40. update_post_meta not working in a loop
  41. Get draggable widgets on Edit Post page
  42. Custom code for WordPress dynamic menu
  43. Custom fields for custom post type
  44. Checked() function on a multidimensional array
  45. What is the best way to store a few fields?
  46. Delist entries in the_loop
  47. Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working
  48. How can I add a simple custom field to my plugin?
  49. Ajax is not working in a loop
  50. WP nonce field checkbox prints checked=’checked’ outside input field
  51. Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
  52. How to save post meta as an array in Gutenberg?
  53. per blog metadata for plugin
  54. How to format custom fields when editing an attachment?
  55. Using delete_post_meta for deleting multiple selected options
  56. Get audio metadata on file upload
  57. Plugin can’t be activated [closed]
  58. Remove Meta-boxes (Yoast SEO plugin) [duplicate]
  59. Is there a way to add a link with add_post_meta?
  60. Adjust query on single
  61. how to add custom fields into new & update post page?
  62. Customise Grouped Product display in Woocommerce with custom column
  63. Why is $_POST empty when saving custom Meta Box?
  64. Condition to check previous next article post title
  65. register_meta not showing custom post type metabox data in rest api
  66. WP_Query not ordering correctly
  67. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  68. Adding customs fields on each product on the cart
  69. Insert, update or remove data from database (usermeta)
  70. add_meta_box does not display meta box in Admin
  71. Unexpected issue when using attachment_fields_to_edit filter
  72. WordPress delete mysql rows with string
  73. How to get post that has non zero or greater than zero meta value
  74. Saving post meta
  75. How and when would I implement some code which would take data from one part of the Db and put it in another?
  76. Include add_post_meta in a plugin
  77. How can i call from custom fields to the category editor?
  78. I want to display the content of a text field only if it has been entered
  79. Create Unique and Customized User ID for Website Members in WordPress
  80. Can I log the searches that are returning 404 in the DB?
  81. A better way of getting draft posts that has a particular post meta using get_posts function
  82. Custom fields in the billing address section woocommerce
  83. Add File field in WooCommerce Box office plugin
  84. modify buddpress adminbar only in admin pages
  85. How to specify widget order or css name via script?
  86. How do you filter get_media_items by mime type in a custom media upload tab?
  87. Deactivate plugin on registration
  88. get_post_meta of multiple posts?
  89. get all posts with certain meta data
  90. How to view plugin ratings?
  91. get_categories exclusion issues
  92. How to conditionally include a custom field on category editor screen not category “add” screen
  93. How to filter manage categories listing
  94. How to add ‘use_desc_for_title = 0’ to all wp_list_categories calls?
  95. Are custom posts delete by unregistering post type
  96. Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
  97. If I want to create new taxonomies (e.g. Project / Documents / Etc…) is it better to create them in the theme’s functions.php or within a plugin? [duplicate]
  98. Enqueue Script in custom plugin before other
  99. How can I start Plugin Development?
  100. Is there such a thing as a WordPress console?
Categories plugin-development Tags custom-field, plugin-development, post-meta
Reposition the widget sidebar in Appearance->Widgets
WP was redirecting to install.php, I installed again and replaced old files with new one but lost all data

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress