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
- Possible to search by author name with default WordPress search function?
- Breadcrumbs showing Parent and Child Pages
- Influence of WordPress functions on site speed
- When new user register then add new user role
- Remove bulk actions based on user role or capabilities
- Set first oembed in post to a global variable or function
- wp_delete_attachment
- WordPress registration and contact form 7 [closed]
- Woocommerce checkout field maxlength, make input number field only (postcode)
- My simple custom shortcode is not longer working (possibly due to upgrade to WordPress 4.4 ?)
- PHP files included in functions.php don’t seem to work
- Register and enqueue style.css custom theme
- WordPress shortcode attributes for database SELECT?
- What do the schemes login, login_post, admin, and relative mean?
- Display images that are not in the content
- How do display most popular post from a year earlier to the day?
- Pagination in relation to archive.php
- Creating A New Admin Menu Tab For Theme Options
- Incorrect redirect after commenting
- Run wp_kses_decode_entities on atom feed?
- Function extending with if query in functions.php
- Turn get_posts as string into an array for use in theme admin options
- How to inherit field value from parent post into in child / sub post
- Why get_user_by() doesn’t work in my code?
- Can’t switch to a child theme using filters template, option_template and option_stylesheet
- What is wrong with code added to functions.php to selectively show styles based on login state
- Changing where my author box is printed
- functions.php return custom text
- WordPress Categories: Function using custom SQL to return array of specific category IDs
- Change category display name function
- Writing a function for WP Cron to run a SQL command daily
- add product thumbnail to checkout page only and include variation name
- Lost Your password Hook Not Showing Up
- Function/way to redirect to specific page whenever a specific text occurs on homepage?
- Get child-pages slugs of current page into js-file
- Frontend Feature image upload not work
- Sending Messages Back to the Template After Processing?
- Shortcode to eliminate and replace with
- I want to split this into two functions
- Filter to strip unnecessary attributes
- Will my WordPress site become vulnerable after adding this functions which allows more HTML tags for subscribers?
- get_post_class() not working well