{"id":1590,"date":"2025-12-24T14:29:12","date_gmt":"2025-12-24T20:29:12","guid":{"rendered":"https:\/\/docs.joedolson.com\/my-calendar\/?p=1590"},"modified":"2025-12-24T14:29:15","modified_gmt":"2025-12-24T20:29:15","slug":"custom-field-api","status":"publish","type":"post","link":"https:\/\/docs.joedolson.com\/my-calendar\/custom-field-api\/","title":{"rendered":"Custom Field API"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">My Calendar has a custom field API to create additional fields for use in your events. <a href=\"https:\/\/www.joedolson.com\/my-calendar-pro\/\">My Calendar Pro<\/a> includes a tool for <a href=\"https:\/\/docs.joedolson.com\/my-calendar-pro\/custom-fields\/\">creating and managing custom fields<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/joedolson\/plugin-extensions\/blob\/master\/my-calendar\/my-calendar-custom-fields.php\">Custom Fields API demo file on Github<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create Input Field<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * Add custom fields that are sortable in My Calendar Pro.\n *\n * @param array   $fields Array of fields available in Pro.\n * @param boolean $has_data If true, this is an event being edited or corrected.\n * @param object  $event The event object saved.\n * @param string  $context 'public' or 'admin', depending on whether this is being rendered in the Pro submissions form or WP Admin.\n *\n * @since My Calendar Pro 2.0.0\n *\n * @return array of fields\n *\/\nfunction mcs_event_email( $fields, $has_data, $event, $context ) {\n\tif ( $has_data ) {\n\n\t\t$post_id = $event->event_post;\n\t\t\/* Any custom fields are saved as custom post meta *\/\n\t\t$email = get_post_meta( $post_id, '_mc_event_email', true );\n\t} else {\n\t\t$email = '';\n\t}\n\t$form = \"&lt;p>&lt;label for='event_email'>\" . __( 'Contact Email', 'textdomain' ) . \"&lt;\/label> &lt;input type='email' name='event_email' id='event_email' value='\" . esc_attr( $email ) . \"' \/>&lt;\/p>\";\n\t$fields&#91;'event_email'] = $form;\n\n\treturn $fields;\n}\nadd_filter( 'mc_custom_fields', 'mcs_event_email', 10, 5 );<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Save Custom Field into Post Meta<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * Save custom fields into post meta.\n *\n * @param int $post_id ID of the post where event meta is saved.\n * @param array $post $_POST array\n * @param array $data Checked array of My Calendar data after processing.\n * @param integer event_id ID of event in my_calendar custom table.\n *\n**\/\nadd_action( 'mc_update_event_post', 'my_event_email_save', 10, 4 );\nfunction my_event_email_save( $post_id, $post, $data, $event_id ) {\n\tif ( is_email( $post&#91;'event_email'] ) ) {\n\t\t$email = sanitize_text_field( $post&#91;'event_email'] );\n\t\tupdate_post_meta( $post_id, '_mc_event_email', $email );\n\t} \n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add custom field into Template Tags<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * Add custom field into template tags array.\n *\n * @param array $details Array of template tags as $tag => $value\n * @param object $event Event object as fetched from database.\n *\n * @return array $details\n**\/\nadd_filter( 'mc_filter_shortcodes', 'my_event_email_tag', 10, 2 );\nfunction my_event_email_tag( $details, $event ) {\n\t$post_id = $event->event_post;\n\t\/* Will be used as {contact_email} in templates. *\/\n\t$details&#91;'contact_email'] = get_post_meta( $post_id, '_mc_event_email', true );\n\t\n\treturn $details;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>My Calendar has a custom field API to create additional fields for use in your events. My Calendar Pro includes a tool for creating and managing custom fields. Custom Fields API demo file on Github Create Input Field Save Custom Field into Post Meta Add custom field into Template Tags<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[],"class_list":["post-1590","post","type-post","status-publish","format-standard","hentry","category-tools"],"_links":{"self":[{"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/posts\/1590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/comments?post=1590"}],"version-history":[{"count":1,"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/posts\/1590\/revisions"}],"predecessor-version":[{"id":1591,"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/posts\/1590\/revisions\/1591"}],"wp:attachment":[{"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/media?parent=1590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/categories?post=1590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.joedolson.com\/my-calendar\/wp-json\/wp\/v2\/tags?post=1590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}