Try this:
add_action('publish_post', 'dp_expiry');
function dp_expiry( $data ) {
/*adds 2 weeks onto the current date in unix epoch format*/
$dp_new_expiry_date = (strtotime( current_time( 'mysql' ) ) + 1209600);
/*converts unix timstamp back to yyyy-mm-dd format like you required*/
$dp_new_expiry_date_conv = date("Y-m-d", $dp_new_expiry_date);
update_post_meta( $data['post_id'], 'postexpiry', $dp_new_expiry_date_conv );
}
Related Posts:
- what is correct way to hook when update post
- Check php version before theme activation
- How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
- Prevent publish status/date saved on transition_post_status hook
- How to Remove a Filter from the Admin List Table?
- Hooking new functions to actions + passing parameters
- Find variables available at a given hook
- Delete option value from array using update_option()
- action hook wp_head higher priority as all other plugins/hooks
- Remove an action hook within a Class
- How to pass arguments to add_action() or retrieve return value of called function?
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Adding widgets to my plugin page instead of WordPress dashboard
- Adding function to Genesis genesis_header [closed]
- Modify custom field input data before creating a new post
- Should `wp_login` be used since it’s deprecated?
- How to catch wordpress post ID when it’s published
- WordPress redirect redirecting too many times or not at all
- Can not add admin notices from the edit_user_profile_update hook (notices not being displayed)?
- How to pass hook variable to function?
- Is there way to toggle the publish date display?
- Get original value in save_post action hooka
- How do I remove an action hook inside a class that is called by another class?
- Hook into all password resets in WordPress and get password before hashing?
- WordPress HTML Helper
- How to add custom checkout field in user details mail template
- Cannot modify header information – headers already sent
- Is there a hook that I can use when a fatal error occurs?
- Using register_activation_hook in classes
- WordPress and event-driven programming – what is it about?
- Does an activated plugin automatically mean its methods are available to other WP functions?
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- Action ‘save_post’ not working for quick edit
- add_meta_boxes action with refresh on save
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Insert post without actions/hooks
- Woocommerce, recognize the loop of related products
- Unable to set right time in admin and frontend template
- How To Change The Html of Products filtration sidebar in Woocommerce?
- Insert all post IDs in new database table
- How to add a second ‘place order’ button in WooCommerce [closed]
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- wp_loaded hook block script enquequing
- Ajax not working es expected (Returns 0)
- add_action shortcut?
- hook that when page is starting to load
- How to change home or site url using action hooks or filter?
- add element with add_action to posts from a specific category ID
- Remove metabox from WordPress menu editor page?
- Add a product to checkout via form
- Trying to place a custom field after the total section in the checkout page in woocommerce
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Print last modified date only on posts
- How to add an arrow to menu items has submenus
- Don’t insert if permalink is the same?
- action theme mailchimp subscriber fields
- add_action taking an array with the 2nd argument?
- Converting Y-m-d to a date with a Month name? [closed]
- Nested “do” and “add” Actions is possible?
- How would I use this filter to change the output of the date format to “Twitter time”?
- How can I hook into the wp_mail function used by BackWPup?
- Action Hook Inside WordPress Plugin Shortcode
- Add a custom class to the body tag using custom fields
- Prevent post from being published and show error
- Change image data durgin upload
- WordPress Post Block Element not properly parsed with the_content filter
- Issue in displaying the ongoing event and current events in the post
- Use wp_head hook on template page
- remove_action from parent theme using child theme functions.php
- Adding custom field to product category and show it to shop/category shop page
- How to edit post meta data before publishing the post it self wordpress?
- Possible to edit custom date field and display?
- get Woocommerce product format json for WP_Query
- Register/enqueue scripts only on certain admin pages
- Is there an option to execute javascript file only on plugin activation
- Help hooking into user_register
- Send Notification after post published was working but stopped after the last WP update
- Why should I need to add init action to include PHP file to WordPress Plugin?
- Grouping posts by date
- remove_action() not working in page template – Genesis
- WordPress change post date format from english to japanese
- How to hook into the subscriber /wp-admin/index.php page?
- Why transition_post_type hook is called twice for the same post?
- Add two or multiple functions in WordPress Post or Page
- Submit to itself don’t work
- Adding a number to a date
- How can I move the posted-on date above the post and below the entry-header?
- How does add_action ‘comment_post’ work?
- Custom action on comment post
- Edit the Publish Widget Options
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- Change Checkout “Place Order” text if cart has a specific product
- Why a class property becomes empty?
- understanding wp_next_scheduled
- How to change wp-admin and wp-login urls
- Convert custom field date format to “WordPress default”
- Guests comment form – prevent duplicate email addresses
- Woocommerce – add tracking code to another email template