{"id":6346,"date":"2016-03-02T14:28:12","date_gmt":"2016-03-02T19:28:12","guid":{"rendered":"https:\/\/themespress.ca\/?p=6346"},"modified":"2022-09-10T18:11:00","modified_gmt":"2022-09-10T22:11:00","slug":"wordpress-query-post-by-date","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/wordpress-query-post-by-date\/","title":{"rendered":"WordPress Query Post by Date"},"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 create a query that will display Post Type posts from the last 7 days. We will store our arguments inside a variable, $semaine, and we loop it.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Le Query Post<\/h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>For this example, our Post Type will be <strong>viavideos<\/strong>. Replace it with your own Post Type or replace by <strong>post<\/strong> for your articles.<\/p>\n<p>The <strong>posts_per_page<\/strong> is set to -1 since we want to do a Query Post for 7 days since we don&#8217;t want it to spread across multiple pages. If you want to paginate it, simply specify the number of results you want per page; for example 5.<\/p>\n<p>We will thus create a query with date_query which will fetch the data from the last 7 days. Notice that we specified the status (post_status) needs to be <strong>publish<\/strong> and we added orderby Date.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >WordPress Query Post by Date<\/h2><div id=\"ts-enlighterjs-container-7522758\" 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-7522758\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php \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;posts_per_page&#039;  =&gt; -1, \n&#039;orderby&#039;         =&gt; &#039;date&#039;, \n&#039;order&#039;           =&gt; &#039;DESC&#039;, \n&#039;date_query&#039;      =&gt; array( \n\tarray( \n\t&#039;after&#039;       =&gt; &#039;1 week ago&#039; \n\t)\n) \n)); \nwhile ( $semaine-&amp;gt;have_posts() ) : $semaine-&amp;gt;the_post(); ?&gt;\n\n&lt;!-- Votre contenu --&gt; \n\n&lt;?php wp_reset_query(); ?&gt;\n&lt;?php endwhile; ?&gt;\t<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will create a query that will display Post Type posts from the last 7 days. We will store our arguments inside a variable, $semaine, and we<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/wordpress-query-post-by-date\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4514,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[330,322],"class_list":["post-6346","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-posts","tag-query"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6346","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=6346"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6346\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4514"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}