To save:
// Update and save the field so it can be used in our template
if ( isset( $_POST['input_name'] ) ) {
$data = sanitize_text_field( $_POST['input_name'] );
update_post_meta( $post_id, 'field_name', $data );
}
To read:
$data = get_post_meta( $post_id, 'field_name', true );
// With post object, a leaner, cleaner method:
$data = $post->field_name;
There’s no need to register another metabox & write another callback. Just duplicate the first batch of echo
in output_source_metabox()
and change the label & name.
To fill the value with the saved data:
echo '<input ... value="' . esc_attr( get_post_meta( $post_id, 'field_name', true ) ) . '" ... />';
You’ll need another “save” block for this second field – just make sure to swap input_name
for the name
of the input, and field_name
for the meta key you want to store this data as.
Related Posts:
- meta_box or custom_field as a second tinymce post-instance?
- Create A Metabox For A Custom Field
- Automatic value for custom fields for posts
- How to I retrieve the ID from the Posts page?
- Hide custom metabox value from custom fields
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- Get post meta retrieving wrong value
- Why my meta boxes won’t show in front post page?
- Display content between two dates?
- Adding an option to post editor to show a site disclaimer or message
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- How can I create a menu items from meta box based on users input
- How set featured posts using checkbox in post edit screen?
- How to get Images included in Post
- How to add metabox for post of specific category
- Convert custom fields to post categories
- Update all posts automatically when using post_meta
- How to batch update post content with custom post meta value
- how to display full post with pagination on home page
- Add custom field to all posts in specific category
- Post & edit a post from front end along with upload, dropdown, and other inputs
- Displaying Page Title on index.php
- How to enqueue scripts depending on post formats?
- Populating a page with content from post custom fields
- Sanitizing `wp_editor();` Values for Database, Edit, and Display
- Using Custom Posts with Metaboxes and Drop-downs
- How to add a custom field after wp post
- Custom fields on a virtual page
- What Is meta_id In wp_postmeta?
- Get a custom field of all posts on current blog page
- Only display posts after current date
- How can I get a post field value using javascript?
- Why won’t my taxonomy query show up?
- Static page does not show my posts
- Custom WordPress Theme: Publish Date and Display Date for posts right beside each other
- How to show single post page as home page
- How can I sort posts by the date and a custom meta field?
- How to display Common posts from specific Tag & Category with Shortcode
- Adding custom fields to bbpress reply form
- Need Help Fixing My Iframes [closed]
- Custom Field created in add_meta_boxes reappearing itself again in the default Custom Metabox
- Automatically add custom fields value to wordpress post
- How to use format post in a pertinent way
- Meta value does not save for scheduled posts
- Unable to restore from backup – how to obtain old blog posts?
- MySql query to get posts with all meta and terms
- Add a custom meta box in the post options that loads some html code in the header
- Trying to retrieve post meta
- Query Posts With Over 1000 Views
- Hooking into the post editing screen for an existing page only
- Redirect to another page using contact form 7? [closed]
- How to create a template for Pages?
- How do I do a page break?
- How to rate a post from Admin Side / Manually?
- How to save meta checkbox WordPress
- Upload attachment from external site
- how to hide empty fields of post category description?
- Add two custom fields as a default to the “new post” page.
- Give posts a particular template based on the assigned category
- Display Featured Posts Grid on Static Page (Gazette)
- how to handle the loop using filling bootstrap grid structure?
- How to validation for sanitize_URL?
- Simple Custom Metabox Not Saving
- Am getting duplicate data from get_posts()
- How to get value in radio input in post meta box?
- Will multiple category descriptions effect my search engine optimization?
- Automate post update for all posts?
- Change modified date to current date when title updated automatically
- Only the most recent post is showing on my category page (working on localhost, not live site)
- Post picker custom field on page
- Display default matabox of posts(add category) wordpress
- Aligning images in the wp editor not working. How do i get this to work in custom theme?
- How to display custom field in product description?
- Adding a drop-down (select tag) option under Menu Settings in WordPress Admin
- I need show posts by customer (Shortcode)
- Display post order ranking within wordpress loop
- Trim excerpt to first paragraph
- Creating Ordered Query using Meta_key
- Auto populate custom fields by post date
- ACF Relationship – Get Parent’s Post Object
- Remove All in One Seo from Posts for Contributors
- How can I set and update the the_date according to a custom field of the post
- How to retrieve a post by inputing the url in a custom field and displaying it on an options page
- Custom fields in normal posts
- How can add metabox for post of specific category before save post and after save post [duplicate]
- WP Query between posts custom fields [duplicate]
- WP Load post with ajax and apply isotope
- Using Post ID and Page ID in same function
- Apply comment to different post (not the current post) [duplicate]
- Display the current post author and his url in the post header
- Add custom field to existing meta box?
- get_post_meta property of non object
- Which hooks are essential for post templates?
- How do I insert a custom field in a user submitted post?
- Convert HTML5 to WordPress theme
- How to make a local “scroll to ID” on post?
- Get posts after calculating meta key
- Is there a block to print post link standalone in a block theme?
- Read more opens attachment
- Image inside the content is replaced with featured image from my older post