• I am working on a database of historical figures and events. I have two custom post types: ‘figures’ and ‘events’. The plan is when reading a post in ‘figures’, the theme would compare the figure’s birth (start) and death (end) dates with posts in ‘events’, and any events post between those two dates would display on the figure’s post. This part I know how to do.

    Some dates are pre-100AD, so each ‘figures’ start and end dates should be a Julian Day (JD) for evaluation. This would be fed from three custom fields each:?start_year,?start_month, and?start_day?for start, and?end_year,?end_month?and?end_day?for end.

    Rather than constantly convert each event into a JD with a separate converter and enter the result manually, I would prefer that the information from each of these fields is automatically fed into either the custom fields?start_jd?or?end_jd, depending.

    Any date before the first day of the Gregorian calendar (Oct 15 1582) would use?juliantojd()?and any date on or after would use?gregoriantojd().

    So if I enter a start date of:
    start_year = 756
    start_month = 12
    start_day = 31

    …hitting “publish” would automatically fill ‘start_jd‘ with the JD ‘1997552‘. Likewise, if I enter an end date of:?
    end_year?= 1870
    end_month?= 9
    end_day?= 20

    …hitting “publish” would automatically fill ‘end_jd‘ with JD ‘2404326‘.

    tl;dr:

    How do/can I get WordPress to automatically convert a Julian or Gregorian calendar date into a JD, and then automatically write that JD into a custom field where it is then saved?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Assuming these custom fields are saved to post meta, you can use the “update_post_metadata” filter to intercept the updating process and do your own. You can then process the submitted data in any manner you wish and save the result. You will need to update or add to the DB directly through the global $wpdb object. When your callback returns any value but null, the default process will be aborted.

Viewing 1 replies (of 1 total)
  • The topic ‘Auto-fill custom field on post creation/modification’ is closed to new replies.