0

I want to use 2 custom fields. One is YEAR field Another is Month field.

automatically these will be filled with post date when I post my blog. How can I do it ?

1
  • 1
    What have you already tried to achieve this?
    – cjbj
    Aug 22, 2016 at 11:42

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.