<?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>WordPress &#8250; Support Topic: Generate a Random post but exclude several post</title>
<link>http://wordpress.org/support/</link>
<description>WordPress &#8250; Support Topic: Generate a Random post but exclude several post</description>
<language>en</language>
<pubDate>Thu, 26 Nov 2009 09:33:19 +0000</pubDate>

<item>
<title>johnkolbert on "Generate a Random post but exclude several post"</title>
<link>http://wordpress.org/support/topic/281985#post-1122255</link>
<pubDate>Wed, 01 Jul 2009 06:04:11 +0000</pubDate>
<dc:creator>johnkolbert</dc:creator>
<guid isPermaLink="false">1122255@http://wordpress.org/support/</guid>
<description>&#60;p&#62;I think you're looking for the &#34;NOT&#34; mysql operator. It negates whatever follows it, so we'll use a &#34;NOT IN&#34;, like this:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;$randomPost = $wpdb-&#38;gt;get_var(&#38;quot;SELECT guid FROM $wpdb-&#38;gt;posts WHERE post_type = &#38;#39;post&#38;#39; AND post_status = &#38;#39;publish&#38;#39; AND ID NOT IN ($pageids) ORDER BY rand() LIMIT 1&#38;quot;);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Hope that helps
&#60;/p&#62;</description>
</item>
<item>
<title>jeffdempsey on "Generate a Random post but exclude several post"</title>
<link>http://wordpress.org/support/topic/281985#post-1110042</link>
<pubDate>Fri, 19 Jun 2009 16:37:05 +0000</pubDate>
<dc:creator>jeffdempsey</dc:creator>
<guid isPermaLink="false">1110042@http://wordpress.org/support/</guid>
<description>&#60;p&#62;I am writing a short script that is designed to generate a random post.  I also have a session where I keep track of the post they have been to already.  I put these pages in a comma delimited variable and attempted exclude them.  Here is my sql statement:&#60;/p&#62;
&#60;p&#62;Here is what it looks like in PHP:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;$randomPost = $wpdb-&#38;gt;get_var(&#38;quot;SELECT guid FROM $wpdb-&#38;gt;posts WHERE post_type = &#38;#39;post&#38;#39; AND post_status = &#38;#39;publish&#38;#39; AND ID &#38;lt;&#38;gt; ($pageids) ORDER BY rand() LIMIT 1&#38;quot;);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Here is what it looks like when the variables are gone:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;SELECT guid FROM hb_posts WHERE post_type = &#38;#39;post&#38;#39; AND post_status = &#38;#39;publish&#38;#39; AND ID &#38;lt;&#38;gt; (1,15,13,20,17,11,5,9,3,0) ORDER BY rand() LIMIT 1&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;I can get the code to work fine if I exclude just one post, so the error is in my (1,1,5,20....).
&#60;/p&#62;</description>
</item>

</channel>
</rss>
