{"id":7325527,"date":"2016-04-27T15:57:11","date_gmt":"2016-04-27T15:57:11","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/exclude-past-events-from-wordpress-serach\/"},"modified":"2016-08-31T16:59:48","modified_gmt":"2016-08-31T16:59:48","slug":"exclude-past-events-from-wordpress-serach","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/exclude-past-events-from-wordpress-serach\/","title":{"rendered":"Exclude Past Events from WordPress Serach"},"content":{"rendered":"<p>Hello,<\/p>\n<p>I am trying to add code to my child theme functions.php to exclude past events from the standard WordPress Search. I have the code blow from another thread, but it is not working. Any help is appreciated, as I see this is an issue that many are trying to resolve.<\/p>\n<pre><code>add_action( &#039;pre_get_posts&#039;, function( $query ) {\n\n\tif ( ! is_admin() &amp;&amp; $query-&gt;is_main_query() &amp;&amp; $query-&gt;is_search() ) {\n\n\t  \t$today = date(&#039;Y-m-d&#039;);\n\n\t\t$meta_query = array(\n\n\t\t&#039;relation&#039; =&gt; &#039;or&#039;,\n\n\t\t\tarray(\n\n\t\t\t&#039;key&#039;=&gt;&#039;event_start_date&#039;,\n\n\t\t\t&#039;value&#039;=&gt;current_time( &#039;Y-m-d&#039; ),\n\n\t\t\t&#039;compare&#039;=&gt;&#039;&gt;=&#039;,\n\n\t\t\t&#039;type&#039; =&gt; &#039;DATE&#039;\n\n\t\t\t),\n\n\t\t\tarray(\n\n\t\t\t\t\t&#039;key&#039;     =&gt; &#039;event_start_date&#039;,\n\n\t\t\t\t\t&#039;compare&#039; =&gt; &#039;NOT EXISTS&#039;,\n\n\t\t\t\t),\n\n\t\t);\n\n\t\t$query-&gt;set(&#039;meta_query&#039;,$meta_query);\n\n\t}\n\n});<\/code><\/pre>\n<p>https:\/\/wordpress.org\/plugins\/events-manager\/<\/p>\n","protected":false},"template":"","class_list":["post-7325527","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/7325527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/7325527\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=7325527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}