There is a hook called save_posts
so you need to hook a function into that post like
add_action('save_posts','store_date');
function store_date(){
if(get_post_type()=='post'){
$month=get_the_date('M');
$year=get_the_date('Y');
update_post_meta(get_the_ID(),'month-field',$month);
update_post_meta(get_The_ID(),'year-field',$year);
}
}
This should be all you need
Here are additonal links to save_posts and update_post_meta
Related Posts:
- How to display custom field in woocommerce orders in admin panel?
- Programatically add options to “add new” custom field dropdown
- Get a list of all available fields in the User Profile
- Enabling shortcodes for custom fields
- Add options to featured image
- Authors details such as social media links, emails etc → Is this Meta or something else?
- Assign category using custom field?
- Function to Download External Images to My Site
- Checked() showing up twice in custom fields
- How to use max and min values of custom fields
- Woocommerce Storefront WordPress Ignore Media Gallery Images and use External 3rd Party Host
- Customizer field value into functions.php variable
- Auto delete post if certain custom field data is empty
- How to display custom option field in woocommerce orders in admin panel?
- How to add a slide toggle to the Woocommerce-Layout__Activity-Panel area in the orders admin page
- What WordPress function to use to get meta value by using meta keys?
- Removing custom meta data
- Change label for registration Fields
- Custom Attachment Caption Fields
- Default Custom Field Value Automatically Update
- WordPress function saves a post twice and updates all posts
- ACF not showing
- How to retrieve the values of a sub-field in the first and last row of an (ACF) repeater inside function?
- How to get correct value from checked()?
- Prevent custom field from being updated after first publish
- Custom Behavior when Adding New Custom Post Type in Dashboard
- Programmatically add Yoast meta description after post save
- Insert Address fields into function
- How to make custom comment fields required
- How add body_class from wp_termmeta
- How do I display a date correctly that is stored in the database as a backwards 8 digit number from Advanced Custom Fields? [closed]
- Sort and display pages with specific custom field (not tag)
- shorthand syntax for custom fields
- Fill empty custom field with other custom field
- Perform function on publish AND save (not just save)
- How to Display WooCommerce Product Price in WooCommerce Archive
- How to change text color depending on the number value (Using javascript)
- wp_set_object_term via js btn frontend
- Populate Product Regular Price with a calculated ACF Field Value
- How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- Create New User Custom Field not Saving
- Creating a “Related Meta” type field?
- How would I correctly implement a new if statement in a child functions file?
- Hide empty custom field
- How To Show Shortcodes In WordPress Custom Fields?
- How to echo the translated custom field?
- How to add function to custom fields when page/post has a password?
- How to exclude posts with empty and non-existent relational custom field with meta_query?
- Dynamically generated Navigation Diagram using Custom Fields
- Define an extra field for all pages (with no plugin?)
- update_post_meta not working in function
- Adding custom field in menu options [duplicate]
- How to display data from custom fields in my custom shortcode?
- Syling Custom Fields echo’s from from functions.php
- Add custom fields after post/page title
- Adding and updating repeating custom field meta data
- Change Post status based on custom field date +1 day
- Can’t get post ID in functions.php?
- Refresh page after form action
- How to customize search result page title?
- Stripping shortcode from custom excerpt function
- Display the number of user comments
- Custom function for user register in wp?
- Child theme functions.php not executing
- How to add background image control to page admin controls?
- Call function without having to wait on response
- Retrieve post modified date for specific post by post ID
- add a function to submit options.php
- wp_is_mobile dequeue not working
- Only let plugin add actions to wp_head & wp_footer on single posts
- Auto Populate Custom Field with Complex Value That Increase by One?
- Function wont fire after custom post type is updated
- Conditional Gravity Forms filter in WordPress Multisite
- When a user logs in, how can they view the website instead of the admin menu?
- What does this code do? (Injected code hacked)
- Is my code correct to enqueue CSS on a specific page?
- WordPress function only executes once
- Dequeue Script Using Functions.php
- Using $WPDB to create simple array to check against user entered value
- Create custom function for hero image
- How to add data to a custom field at the wp_users table?
- Remove a Plugin function through theme’s function.php?
- If is_single in functions.php
- How to conditionally add a widget via a hook in functions.php
- Unescape attribute the_title() on CDATA in RSS feed
- get_image_tag() html output : empty src attribute
- Warning at top of website & top menu gone
- Show ‘Add to Cart’ on Out of Stock products
- Pass post ID from archive template to functions file
- get_comments not working properly after WordPress v4.4 update
- What add_action reference should I be using or should I use do_action?
- Allow the access over wp-login.php
- Create input select image URL?
- Including one page with WordPress functions into another
- Dynamically Generating User Meta Field
- Check if there is an post to be published in future
- Unhook the comment form in Buddypress
- is_preview() always return false
- Customizer cuistom CSS Priority ordre Issue