{"id":13079422,"date":"2020-07-06T18:32:17","date_gmt":"2020-07-06T18:32:17","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/custom-loop-9\/"},"modified":"2020-07-06T18:32:17","modified_gmt":"2020-07-06T18:32:17","slug":"custom-loop-9","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/custom-loop-9\/","title":{"rendered":"Custom loop"},"content":{"rendered":"<p>Hi,<\/p>\n<p>I have this filter on my theme functions.php . As you can see, this loops through posts and displays only posts that have a custom field called calendar_date filled with a date &gt;= today date. So that, we <strong>display only upcoming events<\/strong>.<\/p>\n<p><strong>How can we do the same thing with Swift theme ?<\/strong><\/p>\n<pre><code>function my_events_ie($query) {\n\n  if (!is_admin() &amp;&amp; is_singular() &amp;&amp; $query-&gt;is_main_query()) {\n\n    $query-&gt;set(&#039;posts_per_page&#039;, -1);\n    $query-&gt;set(&#039;no_found_rows&#039;, true);\n    $query-&gt;set( &#039;meta_key&#039;, &#039;calendar_date&#039; );\n    $query-&gt;set( &#039;order&#039;, &#039;ASC&#039;);\n    $query-&gt;set( &#039;meta_query&#039;, array(\n        array(\n            &#039;key&#039;     =&gt; &#039;calendar_date&#039;,\n            &#039;compare&#039; =&gt; &#039;&gt;=&#039;,\n            &#039;value&#039;   =&gt; current_time(&#039;Y-m-d&#039;),\n            &#039;type&#039;    =&gt; &#039;DATE&#039;,\n        )\n    ) );\n }\n\n  \/\/return $query;\n\n}\n\nadd_filter(&#039;pre_get_posts&#039;, &#039;my_events_ie&#039;);<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-13079422","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13079422","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\/13079422\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13079422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}