Support

Account

Home Forums ACF PRO Update post_meta with ACF date value

Solved

Update post_meta with ACF date value

  • Hy,

    I am using ACF date picker to create a start date for my cpt events, called ‘eveniment’.
    The date field is called ‘data_incepe’

    I am trying t achieve the folowing:

    When i save or update the CPT with ACF on it, i would like to create another post_meta called ‘calendar_data’ that will get the same value as ‘data_incepe’.

    I have tried a dozen of solutions, buti think this is over my head.
    Can anyone please help me fix this?

    Thank you!

  • You need to create an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/ something like this.

    
    add_filter('acf/save_post', 'my_copy_date_filter', 20);
        // priority is 20 so that it runs after acf has saved the value
    function my_copy_date_filter($post_id) {
      $post_type = get_post_type($post_id);
      if ($post_type != 'eveniment') {
        // not our post type, bail early
        return;
      }
      $date = get_field('data_incepe', $post_id);
      update_post_meta($post_id, 'calendar_data', $date);
    }
    
  • Thank you. I allready solves it,but your code looks cleaner than mine.

    I wqs trying to build a plugin that displays a calendar with cpt and acf custom date.

    I got everithing working, so if anyone needs it,ask it here.

    I will also upload it to wp repository,since i saw a lot of people wqs looking for something like that.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Update post_meta with ACF date value’ is closed to new replies.