See add_meta_box which has a lot of demo code for working with meta fields. Here is the most relevant part for you:
/* Do something with the data entered */
add_action( 'save_post', 'myplugin_save_postdata' );
/* When the post is saved, saves our custom data */
function myplugin_save_postdata( $post_id ) {
// First we need to check if the current user is authorised to do this action.
if ( 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) )
return;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
}
$mydata="something"; // Do something with $mydata
update_post_meta( $post_id, '_my_meta_value_key', $mydata );
}
Related Posts:
- Filtering a WP_Query meta_query by numeric values isn’t working
- Filter a custom field based on selection of another custom field (ACF) [closed]
- ACF Relationships in Custom Post Type Permalink
- How to sort a table of custom posts by column containing custom field
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- Use Custom Post Type as Custom Field
- Display posts if a custom field value is equal to another custom field value
- ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
- Get Custom Field Values by Another Custom Field in WordPress
- wp_update_post based function works on existing posts, but not new posts
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- Query Custom Post Types by date (custom field) range
- Custom Post type and Custom Field WP_Query
- How to change post featured image using a custom field of category?
- Retrieve value of a category’s custom field
- How can I dynamically add a post to a custom post type which uses a custom field?
- Bulk Update Custom Fields for Custom Post Types
- WP_Query order by custom field, then randomly order some of results
- Query custom post type with ACF Date
- Meta Query Not Returning Output Despite Having Matching Values
- ACF From & To Date Validations
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- How to render a custom post type template with custom fields using shortcode
- Order Custom Post Type by Custom Field Value
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- Multiple Frontend Filters Using Advanced Custom Fields
- Integrate Custom Post Type Events into Calendar
- Displaying custom field according to date
- WebP Fallback for Inline Background Image in Style Attribute
- Query based on custom fields start and end date
- How to get a custom type post data when it has a connection with another custom type post?
- List of users that clicked a ‘Join’ button at single post
- How to inherit field value from parent post into in child / sub post
- Custome fields not displayed
- posttype and custom fields on multisite
- How do I get_the_postID() for a custom post that uses ACF repeater field?
- How do I replace the post title with a custom field?
- Sum and count of custom field values
- Group by custom field value (start and end times)
- Custom post types, disable fields
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- Excerpt length: get first paragraph
- How to keep a record of changes to a custom field?
- Having a repeating custom field in admin custom post type, what I’d go better with, for DB’s sake? ACF repeater or query a different post type?
- ACF – Retrieve custom taxonomy from a relationship field
- Create if else for post types in WP_Query ‘post__in’ values
- Updating a custom post status after an expiry date rather than trashing it
- Display Custom Field or Custom Taxonomy in front page /post/product
- How to access repeater field of a custom field?
- Filter posts by their related field’s custom field
- filter using custom fields
- Autofill advanced custom field with user data
- Advanced search form with multiple custom fields
- save_post affect creation and deletion
- How do I display specific custom posts, and how do I edit a post’s singular page?
- Fixed custom fields depending on posttype/category
- Automatically convert standard posts with custom fields to custom post types
- Can’t pick up a field created with Advanced Custom Fields
- Get month and day from a Date Picker custom field
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
- How to show animal lineage/pedigree in WordPress?
- ACF – Query relationship without ID
- Retrieve a post with its ACF repeater fields in wordpress
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Display ACF object field data using Elementor Custom Query
- Post object GUID adding http:/
- Custom Sort Order for Custom Post Type Taxonomy
- Querying custom post type with 2 custom fields (date-range)
- manage posts custom column is not populating data from meta boxes
- Create child page within custom post type
- Add custom field to media attachment image attribute in post editor
- set and unset the custom field value
- Count custom post types with a specific meta value
- Before Delete Post
- WP_Query that filters based on custom relationship field
- Why do I lose the content of meta boxes when I leave the page?
- Returning a list of custom post types excluding those without a specific meta_value
- Custom post type content using custom fields without template
- Plugin – Combine Meta Box Input Fields into single saveble record
- Get Posts by multiple custom fields is not working
- How to query WordPress posts bycustom field with a max characters’ length
- Enable Custom Fields For Custom Post Type When CPT Created Using Plugin
- ACF repeater field usage
- Batch Extract Date from post title and put into ACF custom field
- Display custom post type for specific user
- How to prevent meta data from being edited in a post?
- How can i show ACF in post excerpts
- WP Query from two Custom Post type fields as statement
- ACF meta_key and meta_value break loop
- search results to show individual ACF fields from inside custom posts
- Videos Post Type with Custom Filters
- Adding a Section for Visitors
- Use output of wp_dropdown_categories($args)
- Values show up in custom home page but not in custom post pages
- How to load custom post type plugin after acf options page (or get settings from there another way)?
- Generate slug and meta data if meta field is empty
- WP_Query get posts where post_name is empty
- How to Create a Frontend Html-list Editable in the Backend?
- Update Custom Field daily within 7days