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
- 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
- Is there a way to notify specific users when new posts are published to specific pages?
- Unable to restore from backup – how to obtain old blog posts?
- MySql query to get posts with all meta and terms
- Categories list into registration form
- Add a custom meta box in the post options that loads some html code in the header
- Simultaneous admin updates causes custom fields to not update
- Trying to retrieve post meta
- Query Posts With Over 1000 Views
- Disable sticky option for specific categories
- Cannot retrieve a custom RSS field from posts
- Highlight static blog page link in header
- Hooking into the post editing screen for an existing page only
- Query Posts by Custom Field
- Redirect to another page using contact form 7? [closed]
- How to create a template for Pages?
- How do I do a page break?
- Where WordPress Stores The Custom Fields Values
- How to rate a post from Admin Side / Manually?
- Block editors annoying warnings
- Customize rel=canonical tag for single blog post
- How to save meta checkbox WordPress
- What does WordPress do if I save a post without content/title? [duplicate]
- How to add a class to edit_post_link?
- Get post ID from a link
- Create a list of posts with topic headdings
- Add field to user meta table in database when link is clicked
- Admin – no Featured image choice in create new/page|post
- Edit multiple custom post types while saving a new or edited post
- Upload attachment from external site
- Show metabox value last post excerpt, title and link
- how to hide empty fields of post category description?
- if in category but only with post meta
- Output Post with ACF Fields into other Post
- Updating post meta for checkbox
- Saving Post Data in Another Database
- Add two custom fields as a default to the “new post” page.
- Give posts a particular template based on the assigned category
- How can I tell if a post has been published at least once?
- Display Featured Posts Grid on Static Page (Gazette)
- After ajax image is outside the “ tag
- Edit custom fields in posts list
- Add multiple meta keys to a post at once
- how to handle the loop using filling bootstrap grid structure?
- WP_Query custom field pass the post id
- Adding JS functionality to the Publish button in wp-admin/post.php
- Get post related to particular meta box? [closed]
- Adding a meta box to determine the sidebar [closed]
- How to validation for sanitize_URL?
- If custom field is empty, use one from a previous post
- Cant’ Grab WordPress Built-in Posts Through Loop
- saving/reading custom field value does not work – no value gets POSTed
- Simple Custom Metabox Not Saving
- Change default post style to columns
- How do I allow certain users to make a certain type of post?
- How to add a post class on every post. (on homepage)
- I can’t find the relevant part of the loop in my theme file. How do I find the full content with “More…”
- Adding external field to my post form (admin side) and to post show (frontend side)
- WordPress Architecture as a CMS – Posts & Pages
- How To Use Custom Fields With .mp3 Links
- how can display a post on home screen without images
- 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
- How to save template data into wp_post table (post_content column)
- Override WordPress core post-template.php block template
- Only the most recent post is showing on my category page (working on localhost, not live site)
- Post picker custom field on page
- Add a field in my rest api
- Permanently deleted posts still exist
- Display default matabox of posts(add category) wordpress
- Post meta not working
- Custom Fields – How to get the list of a specific active widget each time it rendered
- created post displaying differently on front end
- 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?
- How to pull latest posts from a specific category
- Problem paginating a subquery on a post
- Saving canvas generated image when saving post causes 404 error
- Adding a drop-down (select tag) option under Menu Settings in WordPress Admin
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- Problem with multi checkboxes value in metabox?
- Moved a website and excerpts don’t work for old posts
- Is there a way to save different data when USER interacts with the same POST?