<?xml version="1.0" encoding="UTF-8"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>ThemeShaper Forums Topic: Only return posts from the last 30 days</title>
<link>http://themeshaper.com/forums/</link>
<description>Help In Shaping WordPress Themes</description>
<language>en</language>
<pubDate>Mon, 20 May 2013 17:35:49 +0000</pubDate>

<item>
<title>BAC on "Only return posts from the last 30 days"</title>
<link>http://themeshaper.com/forums/topic/only-return-posts-from-the-last-30-days#post-10158</link>
<pubDate>Thu, 25 Feb 2010 02:34:49 +0000</pubDate>
<dc:creator>BAC</dc:creator>
<guid isPermaLink="false">10158@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Just in case anyone finds this useful, I solved this by installing the Auto Delete Posts plugin which has the option to move posts over x days to a new category rather than delete. &#60;/p&#62;
&#60;p&#62;I could then place the following code in my main loop just below have_posts with 20 being the category ID&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#38;lt;?php if (in_category(&#38;#39;20&#38;#39;)) continue; ?&#38;gt;&#60;/code&#62;&#60;br /&#62;
ie&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;while (have_posts()) : the_post(); ?&#38;gt;
&#38;lt;?php if (in_category(&#38;#39;20&#38;#39;)) continue; ?&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I also changed Search Unleashed to exclude this category.&#60;/p&#62;
&#60;p&#62;Hope this helps.&#60;/p&#62;
&#60;p&#62;BAC
&#60;/p&#62;</description>
</item>
<item>
<title>BAC on "Only return posts from the last 30 days"</title>
<link>http://themeshaper.com/forums/topic/only-return-posts-from-the-last-30-days#post-10047</link>
<pubDate>Mon, 22 Feb 2010 12:56:10 +0000</pubDate>
<dc:creator>BAC</dc:creator>
<guid isPermaLink="false">10047@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Actually I think I am closer with the following code, however this returns 0 posts??&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// Filter Index Loop
function remove_thematic_index_loop() {
      remove_action (&#38;#39;thematic_indexloop&#38;#39;,&#38;#39;thematic_index_loop&#38;#39;);
}
add_action(&#38;#39;init&#38;#39;,&#38;#39;remove_thematic_index_loop&#38;#39;);

function my_index_loop() {

function filter_where($where = &#38;#39;&#38;#39;) {
//posts in the last 30 days
$where .= &#38;quot; AND post_date &#38;gt; &#38;#39;&#38;quot; . date(&#38;#39;Y-m-d&#38;#39;, strtotime(&#38;#39;-30 days&#38;#39;)) . &#38;quot;&#38;#39;&#38;quot;;

return $where;
}
add_filter(&#38;#39;posts_where&#38;#39;, &#38;#39;filter_where&#38;#39;);
query_posts($query_string);

 while (have_posts()) : the_post(); ?&#38;gt;

          &#38;lt;div id=&#38;quot;post-&#38;lt;?php the_ID(); ?&#38;gt;&#38;quot; class=&#38;quot;&#38;lt;?php thematic_post_class(); ?&#38;gt;&#38;quot;&#38;gt;
              &#38;lt;?php thematic_postheader(); ?&#38;gt;
              &#38;lt;div class=&#38;quot;entry-content&#38;quot;&#38;gt;
&#38;lt;?php thematic_content(); ?&#38;gt;
				&#38;lt;/div&#38;gt;
              &#38;lt;?php thematic_postfooter(); ?&#38;gt;
          &#38;lt;/div&#38;gt;&#38;lt;!-- .post --&#38;gt;

      &#38;lt;?php endwhile;
}
add_action(&#38;#39;thematic_indexloop&#38;#39;, &#38;#39;my_index_loop&#38;#39;);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I tried a simple &#60;/p&#62;
&#60;p&#62;&#60;code&#62;query_posts(&#38;#39;posts_per_page=2&#38;#39;);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62; instead of &#60;/p&#62;
&#60;pre&#62;&#60;code&#62;function filter_where($where = &#38;#39;&#38;#39;) {
//posts in the last 30 days
$where .= &#38;quot; AND post_date &#38;gt; &#38;#39;&#38;quot; . date(&#38;#39;Y-m-d&#38;#39;, strtotime(&#38;#39;-30 days&#38;#39;)) . &#38;quot;&#38;#39;&#38;quot;;

return $where;
}
add_filter(&#38;#39;posts_where&#38;#39;, &#38;#39;filter_where&#38;#39;);
query_posts($query_string);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;And that works and displays only 2 posts so it seems i am on the right track maybe??&#60;/p&#62;
&#60;p&#62;Thanks for any help on this.&#60;/p&#62;
&#60;p&#62;BAC
&#60;/p&#62;</description>
</item>
<item>
<title>BAC on "Only return posts from the last 30 days"</title>
<link>http://themeshaper.com/forums/topic/only-return-posts-from-the-last-30-days#post-10041</link>
<pubDate>Mon, 22 Feb 2010 11:25:56 +0000</pubDate>
<dc:creator>BAC</dc:creator>
<guid isPermaLink="false">10041@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;hi,&#60;/p&#62;
&#60;p&#62;I am still struggling with filtering the main and category loops to only return posts from the last x days.&#60;/p&#62;
&#60;p&#62;This is where I got to but it doesn't seem to be working for me.. Anyone know what I am doing wrong?&#60;/p&#62;
&#60;p&#62;Not sure if I can have a filter within an action like this?&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
function x-days() {&#60;br /&#62;
//based on Austin Matzko's code from wp-hackers email list&#60;br /&#62;
  function filter_where($where = '') {&#60;br /&#62;
    //posts in the last 30 days&#60;br /&#62;
    $where .= &#34; AND post_date &#38;gt; '&#34; . date('Y-m-d', strtotime('-7 days')) . &#34;'&#34;;&#60;br /&#62;
    return $where;&#60;br /&#62;
  }&#60;br /&#62;
add_filter('posts_where', 'filter_where');&#60;br /&#62;
query_posts($query_string);&#60;/p&#62;
&#60;p&#62;}&#60;br /&#62;
add_action('thematic_above_indexloop', 'x-days');&#60;/p&#62;
&#60;p&#62;&#60;/code&#62;
&#60;/p&#62;</description>
</item>
<item>
<title>BAC on "Only return posts from the last 30 days"</title>
<link>http://themeshaper.com/forums/topic/only-return-posts-from-the-last-30-days#post-9864</link>
<pubDate>Tue, 16 Feb 2010 18:09:43 +0000</pubDate>
<dc:creator>BAC</dc:creator>
<guid isPermaLink="false">9864@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;@Devin&#60;/p&#62;
&#60;p&#62;Thanks so much for this, awesome. works a treat :)&#60;/p&#62;
&#60;p&#62;After much searching, I'm still struggling on how to filter the main loop and category loop to only return posts from the last 30 days...&#60;/p&#62;
&#60;p&#62;I need to add the filter mentioned in my original post above, directly above query_posts(). Can anyone point me in the right direction to achieve this? &#60;/p&#62;
&#60;p&#62;Thanks again. &#60;/p&#62;
&#60;p&#62;BAC
&#60;/p&#62;</description>
</item>
<item>
<title>Devin on "Only return posts from the last 30 days"</title>
<link>http://themeshaper.com/forums/topic/only-return-posts-from-the-last-30-days#post-9519</link>
<pubDate>Fri, 05 Feb 2010 04:28:31 +0000</pubDate>
<dc:creator>Devin</dc:creator>
<guid isPermaLink="false">9519@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Hi BAC.  This code is based off a post at Wp-recipes: &#60;a href=&#34;http://www.wprecipes.com/wordpress-hack-how-to-display-ads-on-old-posts-only&#34;&#62;http://www.wprecipes.com/wordpress-hack-how-to-display-ads-on-old-posts-only&#60;/a&#62;  I just tested it on my site and it works.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;function is_old_post($post_id=null){
	$days = 30;
	global $wp_query;
	if(is_single() &#124;&#124; is_page()) {
		if(!$post_id) {
			$post_id = $wp_query-&#38;gt;post-&#38;gt;ID;
		}
	$current_date = time();
	$offset = $days *60*60*24;
	$post_id = get_post($post_id);
	$post_date = mysql2date(&#38;#39;U&#38;#39;,$post_id-&#38;gt;post_date);
	$cunning_math = $post_date + $offset;
	$test = $current_date - $cunning_math;
		if($test &#38;gt; 0){
			$return = true;
		}else{
			$return = false;
		}
		}else{
		$return = false;
		}
	return $return;
}

// The Single Post
function child_single_post() { ?&#38;gt;
			&#38;lt;div id=&#38;quot;post-&#38;lt;?php the_ID(); ?&#38;gt;&#38;quot; class=&#38;quot;&#38;lt;?php thematic_post_class(); ?&#38;gt;&#38;quot;&#38;gt;
&#38;lt;?php if(is_old_post()){ ?&#38;gt;
&#38;lt;p&#38;gt;This post was published more than 30 days ago.&#38;lt;/p&#38;gt;
&#38;lt;?php } ?&#38;gt;
    			&#38;lt;?php thematic_postheader(); ?&#38;gt;
				&#38;lt;div class=&#38;quot;entry-content&#38;quot;&#38;gt;
&#38;lt;?php thematic_content(); ?&#38;gt;

					&#38;lt;?php wp_link_pages(&#38;#39;before=&#38;lt;div class=&#38;quot;page-link&#38;quot;&#38;gt;&#38;#39; .__(&#38;#39;Pages:&#38;#39;, &#38;#39;thematic&#38;#39;) . &#38;#39;&#38;#38;after=&#38;lt;/div&#38;gt;&#38;#39;) ?&#38;gt;
				&#38;lt;/div&#38;gt;
				&#38;lt;?php thematic_postfooter(); ?&#38;gt;
			&#38;lt;/div&#38;gt;&#38;lt;!-- .post --&#38;gt;
&#38;lt;?php
}
add_filter(&#38;#39;thematic_singlepost&#38;#39;, &#38;#39;child_single_post&#38;#39;);&#60;/code&#62;&#60;/pre&#62;</description>
</item>
<item>
<title>BAC on "Only return posts from the last 30 days"</title>
<link>http://themeshaper.com/forums/topic/only-return-posts-from-the-last-30-days#post-9511</link>
<pubDate>Fri, 05 Feb 2010 01:07:47 +0000</pubDate>
<dc:creator>BAC</dc:creator>
<guid isPermaLink="false">9511@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Hey.&#60;/p&#62;
&#60;p&#62;I tried to implement the code at codex into my child theme functions.php to only return posts from the last 30 days, include search results to no avail. (I just pasted it into the functions file)&#60;br /&#62;
&#60;code&#62;&#60;br /&#62;
&#38;lt;?php&#60;br /&#62;
//based on Austin Matzko's code from wp-hackers email list&#60;br /&#62;
  function filter_where($where = '') {&#60;br /&#62;
    //posts in the last 30 days&#60;br /&#62;
    $where .= &#34; AND post_date &#38;gt; '&#34; . date('Y-m-d', strtotime('-30 days')) . &#34;'&#34;;&#60;br /&#62;
    return $where;&#60;br /&#62;
  }&#60;br /&#62;
add_filter('posts_where', 'filter_where');&#60;br /&#62;
query_posts($query_string);&#60;br /&#62;
?&#38;gt;&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Also, does anyone know how to post a message above a single post page when it is over 30 days old.. ie if someone lands from a search engine they get a message saying 'this post is out of date, try these posts' sort of thing?&#60;/p&#62;
&#60;p&#62;Thanks for any help on this.&#60;/p&#62;
&#60;p&#62;BAC
&#60;/p&#62;</description>
</item>

</channel>
</rss>
