<?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>bbPress support forums Topic: bb_query: get topics started within a date range?</title>
<link>http://bbpress.org/forums/</link>
<description>bbPress support forums Topic: bb_query: get topics started within a date range?</description>
<language>en</language>
<pubDate>Sat, 30 Aug 2008 14:44:56 +0000</pubDate>

<item>
<title>mrhoratio on "bb_query: get topics started within a date range?"</title>
<link>http://bbpress.org/forums/topic/bb_query-get-topics-started-within-a-date-range#post-16144</link>
<pubDate>Mon, 12 May 2008 05:21:26 +0000</pubDate>
<dc:creator>mrhoratio</dc:creator>
<guid isPermaLink="false">16144@http://bbpress.org/forums/</guid>
<description>&#60;p&#62;Hey Sam, thanks for making a ticket for this. I was able to query for topics within a date from directly from Wordpress as well. Here's something I wrote to merge &#34;super sticky&#34; bbPress topics into the Wordpress loop. It's a bit of hack, but it brings the &#34;Promote to Front Page&#34; functionality of Drupal into Wordpress/bbPress:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php get_header(); ?&#38;gt;

&#38;lt;?php

//Put Wordpress posts into an array
$wp_posts = $posts;

if (!is_single()){

	//Retrieve first post of previous page (we need this post&#38;#39;s date to query bbPress topics
	$offset=$paged*$posts_per_page+$posts_per_page;
	$first_post_of_previous_page = get_posts(&#38;#39;numberposts=1&#38;#38;offset=&#38;#39;.$offset);

	//First set the start and end dates to limit the query to the bbPress table
	$startdate=(date(&#38;#39;YmdHis&#38;#39;,strtotime($first_post_of_previous_page[0]-&#38;gt;post_date_gmt)));

	//If it&#38;#39;s the most recent page, set end date to today
	if ($paged){
		$enddate=(date(&#38;#39;YmdHis&#38;#39;,strtotime($wp_posts[0]-&#38;gt;post_date_gmt)));
	} else {
		$enddate=gmdate(&#38;#39;YmdHis&#38;#39;);
	}

	//Retrieve &#38;quot;Super Sticky&#38;quot; topics from bbPress tables
	//This assumes your bbPress and Wordpress tables are in the same database
	$bb_topics = $wpdb-&#38;gt;get_results(&#38;quot;SELECT * FROM bb_topics WHERE topic_sticky = 2 AND topic_start_time BETWEEN $startdate AND $enddate ORDER BY topic_start_time DESC&#38;quot;);

	//Map bbPress topics to WordPress posts structure
	foreach($bb_topics as $bb_topic){
		$bb_first_post = $wpdb-&#38;gt;get_results(&#38;quot;SELECT post_text FROM bb_posts WHERE post_position = &#38;#39;1&#38;#39; AND topic_id = $bb_topic-&#38;gt;topic_id&#38;quot;, ARRAY_A);
		$bb_post-&#38;gt;ID = &#38;quot;forum_topic_&#38;quot;.$bb_topic-&#38;gt;topic_id;
		$bb_post-&#38;gt;post_author = $bb_topic-&#38;gt;topic_poster;
		$bb_post-&#38;gt;post_date = $bb_topic-&#38;gt;topic_start_time;
		$bb_post-&#38;gt;post_content = $bb_first_post[0][post_text];
		$bb_post-&#38;gt;post_title = $bb_topic-&#38;gt;topic_title;
		$bb_post-&#38;gt;post_status = &#38;quot;publish&#38;quot;;
		$bb_post-&#38;gt;comment_status = &#38;quot;open&#38;quot;;
		$bb_post-&#38;gt;ping_status = $bb_topic-&#38;gt;post_id;
		$bb_post-&#38;gt;post_name = &#38;quot;forums/topic/&#38;quot;.$bb_topic-&#38;gt;topic_slug;
		$bb_post-&#38;gt;post_type = &#38;quot;post&#38;quot;;
		$bb_post-&#38;gt;comment_count = $bb_topic-&#38;gt;topic_posts-1;

		//add bbPress topic to Wordpress posts array
		$wp_posts[] = $bb_post;

	};

	//Create function to sort array of posts by date
	function compare($x, $y){
		if ( $x-&#38;gt;post_date == $y-&#38;gt;post_date )
			return 0;
		else if ( $x-&#38;gt;post_date &#38;lt; $y-&#38;gt;post_date )
			return 1;
		else
			return -1;
	}

	//Sort array
	usort($wp_posts,&#38;#39;compare&#38;#39;);
}

?&#38;gt;

	&#38;lt;div id=&#38;quot;content-box&#38;quot; class=&#38;quot;span-8&#38;quot;&#38;gt;

		&#38;lt;div id=&#38;quot;content-area&#38;quot; class=&#38;quot;clearfix&#38;quot;&#38;gt;

&#38;lt;?php if ($wp_posts): ?&#38;gt;
	&#38;lt;?php foreach ($wp_posts as $post): ?&#38;gt;
		&#38;lt;?php setup_postdata($post); ?&#38;gt;

			&#38;lt;div class=&#38;quot;entry&#38;quot;&#38;gt;

				&#38;lt;div class=&#38;quot;entry-header clearfix&#38;quot;&#38;gt;

					&#38;lt;div class=&#38;quot;info span-2&#38;quot;&#38;gt;
						&#38;lt;a href=&#38;quot;&#38;lt;?php the_permalink(); ?&#38;gt;#comments&#38;quot; class=&#38;quot;comment-activity&#38;quot;&#38;gt;&#38;lt;?php comments_number(&#38;#39;&#38;lt;strong&#38;gt;Post comment&#38;lt;/strong&#38;gt;&#38;#39;, &#38;#39;&#38;lt;strong&#38;gt;1&#38;lt;/strong&#38;gt; Comment&#38;#39;, &#38;#39;&#38;lt;strong&#38;gt;%&#38;lt;/strong&#38;gt; Comments&#38;#39; );?&#38;gt;&#38;lt;/a&#38;gt;
					&#38;lt;/div&#38;gt;&#38;lt;!-- end info --&#38;gt;

					&#38;lt;div class=&#38;quot;content span-6 last&#38;quot;&#38;gt;
						&#38;lt;h2&#38;gt;&#38;lt;a href=&#38;quot;&#38;lt;?php the_permalink(); ?&#38;gt;&#38;quot; rel=&#38;quot;bookmark&#38;quot; title=&#38;quot;Permanent Link to &#38;lt;?php the_title(); ?&#38;gt;&#38;quot;&#38;gt;&#38;lt;?php the_title(); ?&#38;gt;&#38;lt;/a&#38;gt;&#38;lt;/h2&#38;gt;
					&#38;lt;/div&#38;gt;&#38;lt;!-- end content --&#38;gt;

				&#38;lt;/div&#38;gt;&#38;lt;!-- end entry-header --&#38;gt;

				&#38;lt;div class=&#38;quot;entry-content clearfix&#38;quot;&#38;gt;

					&#38;lt;div class=&#38;quot;info span-2 clearfix&#38;quot;&#38;gt;
						&#38;lt;p&#38;gt;&#38;lt;strong&#38;gt;&#38;lt;?php the_author() ?&#38;gt;&#38;lt;/strong&#38;gt;&#38;lt;br /&#38;gt;
						&#38;lt;?php the_time(&#38;#39;M j, Y&#38;#39;); ?&#38;gt;
						&#38;lt;/p&#38;gt;
						&#38;lt;p class=&#38;quot;share-this&#38;quot;&#38;gt;&#38;lt;?php akst_share_link(); ?&#38;gt;&#38;lt;/p&#38;gt;

						&#38;lt;p class=&#38;quot;post-comment&#38;quot;&#38;gt;&#38;lt;a href=&#38;quot;&#38;lt;?php the_permalink(); ?&#38;gt;#respond&#38;quot;&#38;gt;Comment&#38;lt;/a&#38;gt;&#38;lt;/p&#38;gt;

					&#38;lt;/div&#38;gt;&#38;lt;!-- end info --&#38;gt;

					&#38;lt;div class=&#38;quot;content span-6 last clearfix&#38;quot;&#38;gt;

						&#38;lt;?php the_content(&#38;#39;Click to continue&#38;#39;); ?&#38;gt;

						&#38;lt;p class=&#38;quot;entry-tags&#38;quot;&#38;gt;&#38;lt;?php the_tags(&#38;#39;&#38;lt;strong&#38;gt;Posted in: &#38;lt;/strong&#38;gt;&#38;#39;, &#38;#39;, &#38;#39;, &#38;#39;&#38;#39;); ?&#38;gt; &#38;lt;/p&#38;gt;

					&#38;lt;/div&#38;gt;&#38;lt;!-- end content --&#38;gt;	

				&#38;lt;/div&#38;gt;&#38;lt;!-- end entry-content --&#38;gt;

			&#38;lt;/div&#38;gt;&#38;lt;!-- end entry --&#38;gt;

						&#38;lt;?php endforeach; ?&#38;gt;

			&#38;lt;?php include (TEMPLATEPATH . &#38;#39;/navigation.php&#38;#39;); ?&#38;gt;

		&#38;lt;?php else : ?&#38;gt;

			&#38;lt;h2 class=&#38;quot;page_header center&#38;quot;&#38;gt;Not Found&#38;lt;/h2&#38;gt;
			&#38;lt;div class=&#38;quot;entry&#38;quot;&#38;gt;
				&#38;lt;p class=&#38;quot;center&#38;quot;&#38;gt;Sorry, but you are looking for something that isn&#38;#39;t here.&#38;lt;/p&#38;gt;
				&#38;lt;?php include (TEMPLATEPATH . &#38;quot;/searchform.php&#38;quot;); ?&#38;gt;
			&#38;lt;/div&#38;gt;

		&#38;lt;?php endif; ?&#38;gt;

		&#38;lt;/div&#38;gt;&#38;lt;!-- end content-area--&#38;gt;

	&#38;lt;/div&#38;gt;&#38;lt;!-- end content-box --&#38;gt;

	&#38;lt;?php get_sidebar(); ?&#38;gt;

&#38;lt;?php get_footer(); ?&#38;gt;&#60;/code&#62;&#60;/pre&#62;</description>
</item>
<item>
<title>sambauers on "bb_query: get topics started within a date range?"</title>
<link>http://bbpress.org/forums/topic/bb_query-get-topics-started-within-a-date-range#post-16141</link>
<pubDate>Mon, 12 May 2008 02:23:44 +0000</pubDate>
<dc:creator>sambauers</dc:creator>
<guid isPermaLink="false">16141@http://bbpress.org/forums/</guid>
<description>&#60;p&#62;&#60;a href=&#34;http://trac.bbpress.org/ticket/879&#34; rel=&#34;nofollow&#34;&#62;http://trac.bbpress.org/ticket/879&#60;/a&#62;
&#60;/p&#62;</description>
</item>
<item>
<title>sambauers on "bb_query: get topics started within a date range?"</title>
<link>http://bbpress.org/forums/topic/bb_query-get-topics-started-within-a-date-range#post-16133</link>
<pubDate>Mon, 12 May 2008 01:20:19 +0000</pubDate>
<dc:creator>sambauers</dc:creator>
<guid isPermaLink="false">16133@http://bbpress.org/forums/</guid>
<description>&#60;p&#62;BB_Query can't do this at the moment as far as I can tell. It probably should though.&#60;/p&#62;
&#60;p&#62;I'll make a trac ticket to suggest this.&#60;/p&#62;
&#60;p&#62;At the moment you could do two BB_Queries and intersect their results. But that's pretty poor.&#60;/p&#62;
&#60;p&#62;Just be sure if you do use a direct query that you prepare it first. e.g.:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;$startdate=&#38;quot;20070602103049&#38;quot;;
$enddate=&#38;quot;20080212090232&#38;quot;;

$query = $bbdb-&#38;gt;prepare(&#38;quot;SELECT * FROM %s WHERE topic_start_time BETWEEN %s AND %s ORDER BY topic_start_time DESC&#38;quot;, $bbdb-&#38;gt;topics, $startdate, $enddate);
$topics = $bbdb-&#38;gt;get_results($query);&#60;/code&#62;&#60;/pre&#62;</description>
</item>
<item>
<title>mrhoratio on "bb_query: get topics started within a date range?"</title>
<link>http://bbpress.org/forums/topic/bb_query-get-topics-started-within-a-date-range#post-15959</link>
<pubDate>Sun, 04 May 2008 05:00:30 +0000</pubDate>
<dc:creator>mrhoratio</dc:creator>
<guid isPermaLink="false">15959@http://bbpress.org/forums/</guid>
<description>&#60;p&#62;I did some more digging, and it looks a way to do is to not use BB_query at all, but to use $bbdb-&#38;gt;get_results instead:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;/p&#62;
&#60;p&#62;$startdate=&#34;20070602103049&#34;;&#60;br /&#62;
$enddate=&#34;20080212090232&#34;;&#60;/p&#62;
&#60;p&#62;$topics = $bbdb-&#38;gt;get_results(&#34;SELECT * FROM $bbdb-&#38;gt;topics WHERE topic_start_time BETWEEN $startdate AND $enddate ORDER BY topic_start_time DESC&#34;);&#60;/p&#62;
&#60;p&#62;&#60;/code&#62;
&#60;/p&#62;</description>
</item>
<item>
<title>mrhoratio on "bb_query: get topics started within a date range?"</title>
<link>http://bbpress.org/forums/topic/bb_query-get-topics-started-within-a-date-range#post-15954</link>
<pubDate>Sat, 03 May 2008 17:00:17 +0000</pubDate>
<dc:creator>mrhoratio</dc:creator>
<guid isPermaLink="false">15954@http://bbpress.org/forums/</guid>
<description>&#60;p&#62;How do I use bb_query to fetch all topics that were started within a given date range?&#60;/p&#62;
&#60;p&#62;Here's an example found an example of a bb_query code on the bbPress blog:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;/p&#62;
&#60;p&#62;$topic_query = new BB_Query( 'topic',&#60;br /&#62;
	array(&#60;br /&#62;
		'topic_author' =&#38;gt; 'mdawaffe',&#60;br /&#62;
		'started' =&#38;gt; '2007-06',&#60;br /&#62;
		'tag' =&#38;gt; 'bbpress',&#60;br /&#62;
		'order_by' =&#38;gt; 'topic_start_time'&#60;br /&#62;
	)&#60;br /&#62;
);&#60;br /&#62;
$topic_query-&#38;gt;results; // Here's the array of topics the query returned.&#60;/p&#62;
&#60;p&#62;&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;This shows how to get topics that where started on June 2007. But what if I wanted to get all topics that were started between June 2, 2007 10:30:49 PM and February 12, 2008 9:02:32 am?&#60;/p&#62;
&#60;p&#62;I think I may be missing something totally obvious. Any suggestions? I
&#60;/p&#62;</description>
</item>

</channel>
</rss>
