{"id":6286,"date":"2016-08-13T13:52:25","date_gmt":"2016-08-13T17:52:25","guid":{"rendered":"https:\/\/themespress.ca\/?p=6286"},"modified":"2022-09-08T19:06:01","modified_gmt":"2022-09-08T23:06:01","slug":"query-post-type-comparing-two-dates","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/query-post-type-comparing-two-dates\/","title":{"rendered":"Create a Query Post Type Between Two Dates"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>With this tutorial, we will show you a date based query post type stemming from a post meta. Here&#8217;s an example of a <a href=\"https:\/\/codex.wordpress.org\/Class_Reference\/WP_Query\" target=\"_blank\" rel=\"noopener\">WP Query<\/a>.<\/p>\n<p>First step is to create a post meta date which fetches the date value. For example, we have created a post meta called <strong>informations_videos_release_date<\/strong>.<\/p>\n<p>Now we will create a query that will display all the post type published between two specific dates. Meaning that for our exmaple, we will display the videos published between the two selected dates. <\/p>\n<p>We will display videos between 1980 et 1989 by using a comparative meta query comparing to Post Meta Key values.<\/p>\n<p>We could also create a form that would fetch the data between both dates and instead of using 1980 and 1989, we would recuperate the form data.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Create a Query Post Type Between Two Dates<\/h2><div id=\"ts-enlighterjs-container-7266904\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-7266904\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php \n\/\/ Premi&egrave;re valeur de date comparative \n$start = &#039;1980&#039;; \n\/\/ Deuxi&egrave;me valeur de date comparative \n$end = &#039;1989&#039;; \n\/\/ Nous commen&ccedil;ons l&#039;affichage \n$semaine = new WP_Query( \narray( \n&#039;post_type&#039;                  =&gt; &#039;viavideos&#039;, \n&#039;post_status&#039;                =&gt; &#039;publish&#039;,\n&#039;meta_key&#039;                   =&gt; &#039;informations_vidos_date_de_sortie&#039;,\n&#039;showposts&#039;                  =&gt; &#039;200&#039;,\n&#039;orderby&#039;                    =&gt; &#039;rand&#039;,\n&#039;paged&#039;                      =&gt; $paged,\n&#039;order&#039;                      =&gt; &#039;DESC&#039;, \n&#039;meta_query&#039;                 =&gt; array(\n    array(\n    \/\/ On appelle la meta key d&eacute;sir&eacute;e et on compare entre les deux valeurs issus des deux variables\n\t\t&#039;key&#039;       =&gt; &#039;informations_vidos_date_de_sortie&#039;,\n\t\t&#039;value&#039;     =&gt; array($start, $end),\n\t\t&#039;compare&#039;   =&gt; &#039;BETWEEN&#039;,\n\t)\n    )\n));\nwhile ( $semaine-&gt;have_posts() ) : $semaine-&gt;the_post();\n?&gt;\n\n\/\/\/\/ Votre loop ici \/\/\/\/\n\n&lt;?php wp_reset_query(); ?&gt;\n&lt;?php endwhile; ?&gt;<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will show you a date based query post type stemming from a post meta. Here's an example of a WP Query. First step is to create<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/query-post-type-comparing-two-dates\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4538,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[322],"class_list":["post-6286","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-query"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6286"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6286\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4538"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}