{"id":1955094,"date":"2023-03-30T15:02:58","date_gmt":"2023-03-30T19:02:58","guid":{"rendered":"https:\/\/theeventscalendar.com\/knowledgebase\/?post_type=post&#038;p=1955094"},"modified":"2024-08-13T10:09:07","modified_gmt":"2024-08-13T14:09:07","slug":"adding-a-custom-event-status","status":"publish","type":"post","link":"https:\/\/theeventscalendar.com\/knowledgebase\/adding-a-custom-event-status\/","title":{"rendered":"Adding a Custom Event Status"},"content":{"rendered":"\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/3ih1sV6z7jU?si=-dEVgzoBPp9KQSOb\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n\n\n\n<p>Events created with The Events Calendar can have 3 statuses out of the box, which is also supported by the Schema.org <a href=\"https:\/\/schema.org\/Event\" target=\"_blank\" rel=\"noreferrer noopener\">event schema<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scheduled &#8211; <em>this is the default status<\/em><\/li>\n\n\n\n<li>Canceled<\/li>\n\n\n\n<li>Postponed<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Adding a Custom Status<\/h2>\n\n\n\n<p>If you would like to add your own custom status, then you can do it with the help of the following snippet.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter( &#039;tec_event_statuses&#039;, &#039;my_custom_statuses&#039;, 20, 2 );\n \nfunction my_custom_statuses( $statuses, $current_status ) {\n\t$custom_statuses = custom_statuses();\n\n\tforeach ( $custom_statuses as $custom_status ) {\n\t\t$statuses&#x5B;] = &#x5B;\n\t\t\t&#039;text&#039;     =&gt; $custom_status&#x5B; &#039;name&#039; ],\n\t\t\t&#039;id&#039;       =&gt; $custom_status&#x5B; &#039;value&#039; ],\n\t\t\t&#039;value&#039;    =&gt; $custom_status&#x5B; &#039;value&#039; ],\n\t\t\t&#039;selected&#039; =&gt; $custom_status&#x5B; &#039;value&#039; ] === $current_status ? true : false,\n\t\t];\n\t}\n\n\treturn $statuses;\n}\n\nfunction custom_statuses() {\n\t$statuses = &#x5B;\n\t\t&#039;rescheduled&#039;     =&gt; &#x5B;\n\t\t\t&#039;name&#039;   =&gt; &#039;Rescheduled&#039;,\n\t\t\t&#039;value&#039;  =&gt; &#039;rescheduled&#039;,\n\t\t\t&#039;schema&#039; =&gt; &#039;EventRecheduled&#039;,\n\t\t],\n\t\t&#039;suspended&#039;       =&gt; &#x5B;\n\t\t\t&#039;name&#039;   =&gt; &#039;Suspended&#039;,\n\t\t\t&#039;value&#039;  =&gt; &#039;suspended&#039;,\n\t\t\t&#039;schema&#039; =&gt; &#039;&#039;,\n\t\t],\n\t];\n\n\treturn $statuses;\n}\n<\/pre><\/div>\n\n\n<p>Note, that the above snippet will not change the event status that is shown in the event schema. If a custom status is chosen for the event, then it will show up as <code>EventScheduled<\/code> in the event schema.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding the Custom Status to the Event Schema<\/h2>\n\n\n\n<p>To modify the event schema, we will need another snippet.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter( &quot;tribe_json_ld_event_object&quot;, &#039;tec_custom_event_schema&#039;, 30, 3 );\n\nfunction tec_custom_event_schema( $data, $args, $post ) {\n\t$custom_statuses = $this-&gt;custom_statuses();\n\n\t$event_status = get_post_meta( $post-&gt;ID, &#039;_tribe_events_status&#039;, true );\n\n\tif ( array_key_exists( $event_status, $custom_statuses ) ) {\n\t\tif ( $custom_statuses&#x5B; $event_status ]&#x5B; &#039;schema&#039; ] === &#039;&#039; ) {\n\t\t\tunset( $data-&gt;eventStatus );\n\t\t} else {\n\t\t\t$data-&gt;eventStatus = $custom_statuses&#x5B; $event_status ]&#x5B; &#039;schema&#039; ];\n\t\t}\n\t}\n\n\treturn $data;\n}\n<\/pre><\/div>\n\n\n<p>Please note, that <a href=\"https:\/\/schema.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/schema.org<\/a> only supports a handful of event statuses, which you can find <a href=\"https:\/\/schema.org\/EventStatusType\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>If you&#8217;re adding a custom status to your dropdown that is not supported by Schema.org (for example, to use it on the front-end only, you can leave the event status in the schema as the default &#8220;scheduled&#8221; using <code>$data-&gt;eventStatus = 'https:\/\/schema.org\/EventScheduled';<\/code> inside the conditional test, or you can completely remove it like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter( &quot;tribe_json_ld_event_object&quot;, &#039;tec_custom_event_schema&#039;, 30, 3 );\n\nfunction tec_custom_event_schema( $data, $args, $post ) {\n\t$event = tribe_get_event( $post );\n\n\tif ( &#039;my_other_status === $event-&gt;event_status ) {\n\t\tunset( $data-&gt;eventStatus );\n\t}\n\n\treturn $data;\n}\n<\/pre><\/div>\n\n\n<p>Making the custom status show up on the calendar and event pages will require some <a href=\"https:\/\/theeventscalendar.com\/knowledgebase\/guide\/customization\/\">customization<\/a>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-showing-the-custom-event-status-on-the-single-event-page\">Showing the Custom Event Status on the Single Event Page<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-classic-editor\">Classic Editor<\/h3>\n\n\n\n<p>Making the custom event status show up on the single event page is easiest with the following snippet.<\/p>\n\n\n\n<p>Make note of the following in case you want to use a different status than &#8220;Suspended&#8221;:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Checking against the status slug on line 4<\/li>\n\n\n\n<li>Adding the right slug in the class on line 7<\/li>\n\n\n\n<li>Showing the right label on line 10 <\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; highlight: [4,7,10]; title: ; notranslate\" title=\"\">\nadd_filter( &#039;tribe_events_single_event_title_html&#039;, &#039;tec_custom_status_on_single_classic&#039;, 10, 2 );\n\nfunction tec_custom_status_on_single_classic( $title, $event_id ) {\n\t$statuses = &#x5B;\n\t\t&#039;suspended&#039; =&gt; &#039;Suspended&#039;,\n\t\t&#039;custom&#039;    =&gt; &#039;Custom&#039;,\n\t];\n\t$event_status = get_post_meta( $event_id, &#039;_tribe_events_status&#039;, true );\n\n\tif ( array_key_exists( $event_status, $statuses ) ) {\n\t\t$status = &#039;\n        &lt;div class=&quot;tribe-common-b2 tribe-events-status-single-notice&quot;&gt;\n            &lt;div class=&quot;tribe-events-status-single tribe-events-status-single--&#039; . $event_status . &#039;&quot;&gt;\n                &lt;div class=&quot;tribe-events-status-single__header&quot;&gt;\n                    &lt;div class=&quot;tribe-events-status-single__header tribe-events-status-single__header--bold tribe-events-status-single__header--alert-icon&quot;&gt;\n                        &#039; . $statuses&#x5B; $event_status ] . &#039;\n                    &lt;\/div&gt;&#039;;\n\t\tif ( get_post_meta( $event_id, &#039;_tribe_events_status_reason&#039;, true ) ) {\n\t\t\t$status .= &#039;\n                        &lt;div class=&quot;tribe-events-status-single__description&quot;&gt;&#039; .\n\t\t\t           wp_kses_post( get_post_meta( $event_id, &#039;_tribe_events_status_reason&#039;, true ) ) .\n\t\t\t           &#039;&lt;\/div&gt;&#039;;\n\t\t}\n\t\t$status .= &#039;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n        &#039;;\n\n\t\t$title = $status . $title;\n\t}\n\n\treturn $title;\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Events created with The Events Calendar can have 3 statuses out of the box, which is also supported by the Schema.org event schema. Adding a Custom Status If you would like to add your own custom status, then you can do it with the help of the following snippet. Note, that the above snippet will&#8230;<\/p>\n","protected":false},"author":84,"featured_media":1955565,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_swpsp_post_exclude":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"ep_exclude_from_search":false,"footnotes":""},"categories":[24,59,84],"tags":[],"stellar-product-taxonomy":[],"class_list":["post-1955094","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-customizing","category-php-function-snippets","category-theming-overview"],"acf":[],"taxonomy_info":{"category":[{"value":24,"label":"Customizations"},{"value":59,"label":"PHP Functions &amp; Snippets"},{"value":84,"label":"Templating &amp; Layout"}]},"featured_image_src_large":["https:\/\/images.theeventscalendar.com\/kb\/uploads\/2023\/02\/social-share-1024x538.png",1024,538,true],"author_info":{"display_name":"The Events Calendar Team","author_link":"https:\/\/theeventscalendar.com\/knowledgebase\/author\/the_events_calendar_team\/"},"comment_info":0,"category_info":[{"term_id":24,"name":"Customizations","slug":"customizing","term_group":0,"term_taxonomy_id":24,"taxonomy":"category","description":"","parent":0,"count":157,"filter":"raw","term_order":"0","cat_ID":24,"category_count":157,"category_description":"","cat_name":"Customizations","category_nicename":"customizing","category_parent":0},{"term_id":59,"name":"PHP Functions &amp; Snippets","slug":"php-function-snippets","term_group":0,"term_taxonomy_id":59,"taxonomy":"category","description":"","parent":24,"count":127,"filter":"raw","term_order":"0","cat_ID":59,"category_count":127,"category_description":"","cat_name":"PHP Functions &amp; Snippets","category_nicename":"php-function-snippets","category_parent":24},{"term_id":84,"name":"Templating &amp; Layout","slug":"theming-overview","term_group":0,"term_taxonomy_id":84,"taxonomy":"category","description":"","parent":24,"count":59,"filter":"raw","term_order":"0","cat_ID":84,"category_count":59,"category_description":"","cat_name":"Templating &amp; Layout","category_nicename":"theming-overview","category_parent":24}],"tag_info":false,"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1955094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/84"}],"replies":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1955094"}],"version-history":[{"count":10,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1955094\/revisions"}],"predecessor-version":[{"id":1962396,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1955094\/revisions\/1962396"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1955094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1955094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1955094"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1955094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}