{"id":1389903,"date":"2017-11-23T04:13:08","date_gmt":"2017-11-23T12:13:08","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/"},"modified":"2017-11-23T04:13:08","modified_gmt":"2017-11-23T12:13:08","slug":"custom-post-meta-to-show-event-stock-status","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/","title":{"rendered":"Custom post meta to show event stock status"},"content":{"rendered":"<p>Hi,<\/p>\n<p>I have a page on a clients website which uses WP Advanced search to display all the events and allow users to filter, search and order the events. Generally this works well with the filters working as intended.<\/p>\n<p>The client then requested an additional filter to filter by events that are in stock and out of stock.  To filter the events I have to use the post meta attached to the event rather than the product linked to the event.  I have looked and the instock meta is attached to the product which has caused a few issues.<\/p>\n<p>To get around this problem, I wrote a custom function which fires when an order is placed for an event via a WooCommerce hook. The function finds the product ID, gets the stock status of the product and its parent id before adding a custom meta field to the event showing whether it is in stock or out of stock.  In theory this process works and does work, but is quite temperamental and doesn&#8217;t always add the custom post meta of &#8216;In Stock&#8217; or  &#8216;Out of Stock&#8217; correctly to the relevant event.<\/p>\n<p>Can you suggest a better, and possibly simpler way to achieve this?  All I want is for each of the events to have a custom meta field which shows whether the event is in stock or out of stock.  If I have this, the filtering system I have will work perfectly.<\/p>\n<p>Many Thanks<\/p>\n","protected":false},"template":"","class_list":["post-1389903","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>Custom post meta to show event stock status -<\/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\/custom-post-meta-to-show-event-stock-status\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom post meta to show event stock status -\" \/>\n<meta property=\"og:description\" content=\"Hi, I have a page on a clients website which uses WP Advanced search to display all the events and allow users to filter, search and order the events. Generally this works well with the filters working as intended. The client then requested an additional filter to filter by events that are in stock and [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/\" \/>\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\/custom-post-meta-to-show-event-stock-status\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/\",\"name\":\"Custom post meta to show event stock status -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2017-11-23T12:13:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/#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\":\"Ticket Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/event-tickets\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Event Tickets Plus\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/event-tickets\/event-tickets-plus\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Custom post meta to show event stock status\"}]},{\"@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":"Custom post meta to show event stock status -","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\/custom-post-meta-to-show-event-stock-status\/","og_locale":"en_US","og_type":"article","og_title":"Custom post meta to show event stock status -","og_description":"Hi, I have a page on a clients website which uses WP Advanced search to display all the events and allow users to filter, search and order the events. Generally this works well with the filters working as intended. The client then requested an additional filter to filter by events that are in stock and [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/","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\/custom-post-meta-to-show-event-stock-status\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/","name":"Custom post meta to show event stock status -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2017-11-23T12:13:08+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-post-meta-to-show-event-stock-status\/#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":"Ticket Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/event-tickets\/"},{"@type":"ListItem","position":4,"name":"Event Tickets Plus","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/event-tickets\/event-tickets-plus\/"},{"@type":"ListItem","position":5,"name":"Custom post meta to show event stock status"}]},{"@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\/1389903","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\/1389903\/revisions"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1389903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}