Support Forum » User Profile

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Populate Custom Field with Another Custom Field's Data #39619
    PetePete
    Participant

    Thanks guys! I got it sorted in the end with the following:

    function XXXX_readable_month_year_event($post_id) {
        if (get_post_type($post_id) == 'event') {
            $event_date = get_post_meta($post_id, 'event_date', true);
            $readable_date = date('F, Y', $event_date);
            update_post_meta($post_id, 'event_readable_my', $readable_date);
        }
    }
    add_action('save_post', 'XXXX_readable_month_year_event');

    What that does in order is:

    1) Checks the post type is "event"
    2) Gets the field "event_date"
    3) Turns "event_date" into human readable format Month, Year
    4) Adds the readable format as text to the Metabox cusom field "event_readable_my"
    5) Runs on save

    I think I explained badly what I needed to happen originally, but I got there in the end lol

Viewing 1 post (of 1 total)