{"id":1345994,"date":"2017-09-07T08:45:11","date_gmt":"2017-09-07T15:45:11","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/"},"modified":"2017-09-07T08:45:11","modified_gmt":"2017-09-07T15:45:11","slug":"set-default-featured-image-if-not-specified-manually","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/","title":{"rendered":"Set Default Featured Image if Not Specified Manually"},"content":{"rendered":"<p>Howdy folks, <\/p>\n<p>I understand you guys can&#8217;t provide much support for custom coding, and while I&#8217;m not suggesting that this be a feature request, I was wondering if you could point me in the right direction.<\/p>\n<p>I&#8217;m developing a site where I want a default featured image set for a specific category if it is not set manually. My end user will be adding events to a category with the ID &#8217;21&#8217; and I don&#8217;t expect that they will set a featured image, so I want a fallback.<\/p>\n<p>Now, I understand how to <a href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/default-image-for-event-category\/\">display a default image<\/a> if one is not specified, but I actually want to SET the image so that it is called in other areas throughout the website where featured images are displayed. I have a similar function that works for regular post_types, but it isn&#8217;t working for tribe_events. Can you tell me where I&#8217;m wrong here?<\/p>\n<pre><code>\/\/ Featured Image for Tribe Category 21\nfunction default_cat21_featured_image() {\n\tglobal $post;\n\tif(tribe_event_in_category( &#039;21&#039; ) ) {\n\t\t$featured_image_exists = has_post_thumbnail( $event_id );\n\t\tif ( !$featured_image_exists )  {\n\t\t\t$attached_image = get_children( &quot;post_parent=$post-&gt;ID&amp;post_type=attachment&amp;post_mime_type=image&amp;numberposts=1&quot; );\n\t\t\tif ( $attached_image ) {\n\t\t\t\tforeach ( $attached_image as $attachment_id =&gt; $attachment ) {\n\t\t\t\tset_post_thumbnail( $event_id, $attachment );\n\t\t\t\t}\n\t\t\t}\n\telse \tset_post_thumbnail( $event_id, &#039;1504&#039; );\n\t\twp_reset_postdata();\n     \t}\n\t}\n}\nadd_action( &#039;the_post&#039;, &#039;default_cat21_featured_image&#039; );<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-1345994","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Set Default Featured Image if Not Specified Manually -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Set Default Featured Image if Not Specified Manually -\" \/>\n<meta property=\"og:description\" content=\"Howdy folks, I understand you guys can&#8217;t provide much support for custom coding, and while I&#8217;m not suggesting that this be a feature request, I was wondering if you could point me in the right direction. I&#8217;m developing a site where I want a default featured image set for a specific category if it is [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/\",\"name\":\"Set Default Featured Image if Not Specified Manually -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2017-09-07T15:45:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Calendar Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Events Calendar PRO\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Set Default Featured Image if Not Specified Manually\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Set Default Featured Image if Not Specified Manually -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/","og_locale":"en_US","og_type":"article","og_title":"Set Default Featured Image if Not Specified Manually -","og_description":"Howdy folks, I understand you guys can&#8217;t provide much support for custom coding, and while I&#8217;m not suggesting that this be a feature request, I was wondering if you could point me in the right direction. I&#8217;m developing a site where I want a default featured image set for a specific category if it is [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/","name":"Set Default Featured Image if Not Specified Manually -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2017-09-07T15:45:11+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/set-default-featured-image-if-not-specified-manually\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Calendar Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/"},{"@type":"ListItem","position":4,"name":"Events Calendar PRO","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/"},{"@type":"ListItem","position":5,"name":"Set Default Featured Image if Not Specified Manually"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1345994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1345994\/revisions"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1345994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}