Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add_new_arrival_meta( $post_id ) {
- // If this is just a revision, don't check.
- if ( wp_is_post_revision( $post_id ) )
- return;
- // Get all categories and look if the one with the slug new-arrivals is there
- $categories = wp_get_post_categories($post_id);
- $is_new_arrival = array_filter(
- $categories,
- function ($e) {
- return $e->slug == 'new-arrivals';
- }
- );
- // If it is there, then add a post meta
- if($is_new_arrival)
- add_post_meta($post_id,'arrived_at',date('Y-m-d'));
- }
- add_action( 'save_post', 'add_new_arrival_meta' );
Advertisement
Add Comment
Please, Sign In to add comment