You need to escape data while displaying also. Use esc_attr in your case. Try this:
<input type="text" name="field_name" value="<?php echo (!empty($field)) ? esc_attr( $field ) : ''; ?>" />
Check this for full documentation – https://codex.wordpress.org/Data_Validation
Related Posts:
- Proper Way to Sanitize Meta Input
- Sanitizing integer input for update_post_meta
- Should I sanitize custom post meta if it is going to be escaped later?
- Correct processing of `$_POST`, following WordPress Coding Standards
- How to sanitize post meta field value?
- Copy content stored in meta to post content
- Can A Post Meta Field Store multiple values that are not in an array?
- esc_attr on get_post_meta [closed]
- Data not displaying in text field
- Extend file format support for post thumbnails
- How can I get the post ID from a WP_Query loop?
- How to edit a post meta data in a Gutenberg Block?
- How to update/delete array in post meta value?
- Adding an assisting editor box to Post page
- How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
- Get Advanced Custom Fields values before saving [closed]
- How to store post meta in an array?
- adding a URL to a post meta
- update_post_meta() not working when used with WordPress action
- Adding meta data to an attachment post
- Get posts by meta value with date
- Get updated post meta on save_post action?
- Delete post meta conditionally after save post
- Problem With Order Item Meta In Woocommerce
- Job of meta_key meta_value fields in database tables
- Multiple register settings, with same option name – issue
- Best way to save postmeta
- vs WordPress Security
- How to add meta data to WordPress posts?
- How to update Post Meta values through the comment system
- Filtering multiple meta_values
- How add post_meta from user_meta?
- How can I get my iFrame to work with url from post_meta?
- How to use update_post_meta() function properly?
- How to display post view count by date, week and month?
- How do I dynamically call a page/post author into the meta data?
- Set Condition echo function get_post_meta
- Unable to sanitize in customizer and escape in theme without removing ability for user to use “< br >” to insert a line break
- Is it possible to retrieve a post and its metadata at the same time?
- cleaning up safely wordpress wp_postmeta table
- Post meta as array looks like string instead of array
- Why does get_transient() always return string even if integer set?
- Author_meta ONLY if it exists
- How to test the outcome of a wpdb query?
- How do I manage custom meta in post revisions in the Block Editor era?
- Generate metadata for cloud images
- Is there a way to disable post meta caching for development?
- Insert multiple metas in one time
- How to extract data from a post meta
- Get post_meta from specific post [closed]
- How to add tags to post from frontend?
- update_post_meta not working?
- Change wordpress meta tag description using WP functions
- getting the post_id from the post_meta
- troubles with get_post_meta (and saving it)
- Cant create or update meta fields using WordPress REST API
- Filter posts by meta key
- Display current ranking of post as a number in post title
- delete duplicates wp_postmeta
- Post Thumbnail missing when using webp format while sharing
- Bulk Update Post Meta Values from Different Post via Rest Api
- update_post_meta() is not saving the value
- Only show meta on one post type on search results page
- How to register post meta with multi level arrays?
- If I disable screen options, does WP still try to update post meta?
- How to save Checkbox-Options in Plugin Options Page
- Can we have duplicate key pair values in post meta data?
- I created a Custom Meta Box but it is not displaying the value on my post page
- Meta data being pulled from wp-login.php
- Update post meta date always store 1970-01-07
- Is it possible to pass an whole array using custom field in wordpress?
- Get post content before rendering
- wp_insert_post inside save_post adds wrong metadata to inserted post
- Rename image filename using ‘media_handle_upload’
- Update Post metafield of specific categories
- rendering open graph meta tags in wordpress
- Using Self Hosted Video URL With Custom Fields
- Multiple postmeta values to the same post_id/meta_key combination?
- get_post_meta not work in php foreach
- Why are my custom metaboxes not updating the post meta?
- Problem serializing single quote and double quote into post meta
- Storing post_meta fields in array
- Performace on 1 million plus meta fields vs 1 field with 1 million multi array
- Fetching array of postmeta with $wpdb and in_array conditional
- Piklist File Upload
- wp_schedule_event not working
- how to echo/display the custom field value in specific custom field name?
- update_post_meta() not working in bulk option
- How to update the ‘modified_time’ of a post ONLY when content is changed?
- Multiple If else statements on Search Result Page
- Settings api sanatize callback not being triggered
- WordPress join posts with meta values of array type
- Export posts with postmeta without ID?
- get_children filter with postmeta
- How can I display my meta value in a textarea? [closed]
- delete blank space in post_meta empty [closed]
- wordpress query making site very slow
- if condition from post_meta not working in save_post
- I read the postmeta and update it without changing it, then move on to the next record
- How to append $metadata[‘sizes’] to metadata when using ‘wp_generate_attachment_metadata?