{"id":162,"date":"2016-06-06T12:32:34","date_gmt":"2016-06-06T12:32:34","guid":{"rendered":"http:\/\/www.3pixls.com\/blog\/?p=162"},"modified":"2016-06-06T12:34:43","modified_gmt":"2016-06-06T12:34:43","slug":"display-your-most-popular-posts-in-the-last-30-days-without-a-plugin","status":"publish","type":"post","link":"https:\/\/www.3pixls.com\/blog\/display-your-most-popular-posts-in-the-last-30-days-without-a-plugin\/","title":{"rendered":"Display Your Most Popular Posts In the Last 30 Days Without a Plugin"},"content":{"rendered":"<p><img loading=\"lazy\" src=\"http:\/\/www.3pixls.com\/blog\/wp-content\/uploads\/2016\/06\/1357250515What_s_Trending620x2251.jpg\" alt=\"1357250515What_s_Trending620x2251\" width=\"620\" height=\"225\" class=\"alignnone size-full wp-image-166\" srcset=\"https:\/\/www.3pixls.com\/blog\/wp-content\/uploads\/2016\/06\/1357250515What_s_Trending620x2251.jpg 620w, https:\/\/www.3pixls.com\/blog\/wp-content\/uploads\/2016\/06\/1357250515What_s_Trending620x2251-300x109.jpg 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><br \/>\n[php]<br \/>\n&lt;div class=&quot;col-md-12&quot;&gt;<br \/>\n                        &lt;div class=&quot;custom-heading02&quot;&gt;<br \/>\n                            &lt;h2&gt;Trending Articles&lt;\/h2&gt;<br \/>\n                        &lt;\/div&gt;&lt;!&#8211; .custom-heading02 end &#8211;&gt;<br \/>\n                        &lt;?php<br \/>\nfunction filter_where($where = &#8221;) {<br \/>\n    \/\/posts in the last 30 days<br \/>\n    $where .= &quot; AND post_date &gt; &#8216;&quot; . date(&#8216;Y-m-d&#8217;, strtotime(&#8216;-30 days&#8217;)) . &quot;&#8217;&quot;;<br \/>\n    return $where;<br \/>\n}<br \/>\nadd_filter(&#8216;posts_where&#8217;, &#8216;filter_where&#8217;);<\/p>\n<p>query_posts(&#8216;post_type=post&amp;posts_per_page=10&amp;orderby=comment_count&amp;order=DESC&#8217;);<\/p>\n<p>while (have_posts()): the_post(); ?&gt;<br \/>\n                        &lt;div class=&quot;col-md-6 col-sm-12&quot;&gt;<br \/>\n            &lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;&lt;?php the_post_thumbnail( &#8216;medium&#8217;, array( &#8216;class&#8217; =&gt; &#8216;img-responsive&#8217; ) ); ?&gt;&lt;\/a&gt;<br \/>\n            &lt;span&gt;&lt;strong&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt; &lt;?php echo substr(the_title(&#8221;, &#8221;, FALSE), 0, 50); ?&gt;&lt;\/a&gt;&lt;\/strong&gt;&lt;\/span&gt;&lt;br \/&gt;<br \/>\n          &lt;span class=&quot;postdate&quot;&gt;&lt;?php the_time(&#8216;F jS, Y&#8217;) ?&gt; by &lt;?php the_author_posts_link() ?&gt;&lt;\/span&gt;<br \/>\n          &lt;\/div&gt;<br \/>\n          &lt;?php<br \/>\nendwhile;<br \/>\nwp_reset_query();<br \/>\n?&gt;<br \/>\n                        &lt;\/div&gt;<br \/>\n[\/php]<\/p>\n<p>Just add this to your template where you want to use it. No plugins necessary!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[php] &lt;div class=&quot;col-md-12&quot;&gt; &lt;div class=&quot;custom-heading02&quot;&gt; &lt;h2&gt;Trending Articles&lt;\/h2&gt; &lt;\/div&gt;&lt;!&#8211; .custom-heading02 end &#8211;&gt; &lt;?php function filter_where($where = &#8221;) { \/\/posts in the last 30 days $where .= &quot; AND post_date &gt; &#8216;&quot; . date(&#8216;Y-m-d&#8217;, strtotime(&#8216;-30 days&#8217;)) . &quot;&#8217;&quot;; return $where; } add_filter(&#8216;posts_where&#8217;, &#8216;filter_where&#8217;); query_posts(&#8216;post_type=post&amp;posts_per_page=10&amp;orderby=comment_count&amp;order=DESC&#8217;); while (have_posts()): the_post(); ?&gt; &lt;div class=&quot;col-md-6 col-sm-12&quot;&gt; &lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;&lt;?php the_post_thumbnail( &#8216;medium&#8217;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":166,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/posts\/162"}],"collection":[{"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/comments?post=162"}],"version-history":[{"count":4,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/posts\/162\/revisions\/168"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/media\/166"}],"wp:attachment":[{"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/media?parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/categories?post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.3pixls.com\/blog\/wp-json\/wp\/v2\/tags?post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}