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?
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Remove a div from RSS feed
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- Print last modified date only on posts
- user_profile_update_errors hook not executing
- Adding number to date not working [closed]
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Error in custom php function doesn’t exist
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Don’t insert if permalink is the same?
- Return a numerical function value in Customizer controls
- action theme mailchimp subscriber fields
- edit_comment_link is not showing for comment author
- how to make custom ajax handler?
- Are all hooks/functions tied to Kses meant for sanitization?
- How to manually change current date to post date in frontend?
- Copy post to separate database with “add_action(….)”
- Error call_user_func_array() expects parameter 1 to be a valid callback when using image_size_names_choose
- jQuery code not working when included in functions.php
- Why does wp_head hook my functions to the beginning of my source code?
- add_action taking an array with the 2nd argument?
- Pass argument to event hook
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- How to show a users bio on a page
- Convert WordPress date format to jQuery UI Datepicker format
- Converting Y-m-d to a date with a Month name? [closed]
- Override a function defined in wp-includes/comment-template.php
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- Password minimum length in personal subscription [closed]
- How to use a custom hook
- I would like to send a notification email (Asana) whenever something is published (posts, pages, custom post types) [duplicate]
- Nested “do” and “add” Actions is possible?
- Run a code only on theme activation only during first activation
- Change order of custom submenu link in WP Admin?
- Theme activation hook in php class
- How would I use this filter to change the output of the date format to “Twitter time”?
- Theme not calling Jquery properly
- add_action hook for publish_post not working
- Are there action hooks for comments?
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Get access to variable from previous pageview, excluding ajax-calls
- Why does the post_type_link hook everything twice?
- How to get User Time Zone in WordPress?
- How to have different site identity logos on each page on Astra Theme [closed]
- How can I hook into the wp_mail function used by BackWPup?
- How to pass argument to add_action while the method is inside a class?
- Display attribute on shop page after the title
- Get user custom field value on function.php
- Send notification email to admin for every new post published
- Adding function to child theme’s function.php
- Comapare get_user_meta value
- Action Hook Inside WordPress Plugin Shortcode
- Dynamically adding filters
- Woocommerce custom Plugin in wordpress [closed]
- Add a custom class to the body tag using custom fields
- Must filter functions receive all arguments passed to them?
- Why doesn’t global $wp_query not get hooked?
- Creating customized php files in theme folder
- Dynamically Generate Functions and Hooks
- Using php inside javascript [closed]
- Get date function not working
- Prevent post from being published and show error
- Change image data durgin upload
- save_post trigerred twice
- How to sort WooCommerce products page by latest in-stock items first?
- Generate a QR code when creating a new WordPress user
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- Replace a single variable with add_filter
- WordPress Post Block Element not properly parsed with the_content filter
- Filter wordpress posts without searching the keywords in the post content