<html><body bgcolor="#FFFFFF"><div><br>Two ways, both have their drawbacks:</div><div><br></div><div>You'll probably do best by running multiple loops. That way you know exactly where each category of posts begins and ends and you can choose how many you want in each section. You'll also be able to avoid burying a section because you had a run on another section and your most recent n posts are all the same category. </div><div><br></div><div>On the other hand, maybe that's what you want, or maybe you have other ideas. In that case...</div><div><br></div><div>MySQL's <span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.289062); -webkit-composition-fill-color: rgba(175, 192, 227, 0.222656); -webkit-composition-frame-color: rgba(77, 128, 180, 0.222656); ">ORDER BY FIELD($fieldname, ...list of matching entries in the order you want them...) syntax my be what you need. <span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.265625); -webkit-composition-fill-color: rgba(175, 192, 227, 0.199219); -webkit-composition-frame-color: rgba(77, 128, 180, 0.199219); ">You'd have to join the term relationships table, then order by term_taxonomy_id (or go all the way and join the other tables to order by category name)</span></span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.261719); -webkit-composition-fill-color: rgba(175, 192, 227, 0.195312); -webkit-composition-frame-color: rgba(77, 128, 180, 0.195312);"><br></span></div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.28125); -webkit-composition-fill-color: rgba(175, 192, 227, 0.214844); -webkit-composition-frame-color: rgba(77, 128, 180, 0.214844); "><a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field">http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field</a></span><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.269531); -webkit-composition-fill-color: rgba(175, 192, 227, 0.203125); -webkit-composition-frame-color: rgba(77, 128, 180, 0.203125);"><br></span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.277344); -webkit-composition-fill-color: rgba(175, 192, 227, 0.210938); -webkit-composition-frame-color: rgba(77, 128, 180, 0.210938);">If you go that route, the posts_join and posts_orderby filters will be your friends. You'd probably want to hook a function to the pre_get_posts action that checks that the request is for the front page and then applies the filters. You should probably also apply a hook the to remove the filters on loop_end or something like that so they don't disrupt other queries. </span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.273438); -webkit-composition-fill-color: rgba(175, 192, 227, 0.207031); -webkit-composition-frame-color: rgba(77, 128, 180, 0.207031);"><br></span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.277344); -webkit-composition-fill-color: rgba(175, 192, 227, 0.210938); -webkit-composition-frame-color: rgba(77, 128, 180, 0.210938);">--Casey Bisson</span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.273438); -webkit-composition-fill-color: rgba(175, 192, 227, 0.207031); -webkit-composition-frame-color: rgba(77, 128, 180, 0.207031);"><br></span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.277344); -webkit-composition-fill-color: rgba(175, 192, 227, 0.210938); -webkit-composition-frame-color: rgba(77, 128, 180, 0.210938);"><a href="http://MaisonBisson.com">http://MaisonBisson.com</a></span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.277344); -webkit-composition-fill-color: rgba(175, 192, 227, 0.210938); -webkit-composition-frame-color: rgba(77, 128, 180, 0.210938);"><a href="http://Scriblio.net">http://Scriblio.net</a><br></span><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.285156); -webkit-composition-fill-color: rgba(175, 192, 227, 0.21875); -webkit-composition-frame-color: rgba(77, 128, 180, 0.21875);"><br></span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.285156); -webkit-composition-fill-color: rgba(175, 192, 227, 0.21875); -webkit-composition-frame-color: rgba(77, 128, 180, 0.21875);"><br></span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.289062); -webkit-composition-fill-color: rgba(175, 192, 227, 0.222656); -webkit-composition-frame-color: rgba(77, 128, 180, 0.222656); "> SELECT * FROM wp_posts WHERE ID IN(5,10,15,20,25,30) ORDER BY FIELD(ID, 10,30,20,25,5,15) Probably not efficient for very large result sets, but... On Mon, Feb 15, 2010 at 7:40 PM, Andy Skelton <skeltoac at <a href="http://gmail.com">gmail.com</a>> wrote: > The second example uses a subquery to find the ID's. Subqueries rock. > You can use them to get the set of ID's from other tables in your > database. But this example has an important limitation: you can't > control the order of the final result set by the order of the subquery > in an IN clause. > </span></div><div><br></div><div><br></div><div><br>On Jun 13, 2010, at 6:37 PM, Alex Bluesummers <<a href="mailto:MrBluesummers@MrBluesummers.com">MrBluesummers@MrBluesummers.com</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div>First person with an elegant answer gets it!<div><br></div><div><b>Question</b></div><div>How do I order posts in the loop by whether or not it is in a category, then by date?</div><div><br></div><div><b>Context</b></div><div>
<b></b>Suppose I have 10 posts, of which 5 are in the category "Sports" and 5 are in the category "Blog News". Both "Sports" and "Blog News" posts are mixed together chronologically. "Sports" and "Blog News" posts share other categories and tags. I want both types of posts to be present in the loop regardless of whether it's the front page or category archive view, but ordered by "Sports" and "blog news" and then by date. How is this most elegantly accomplished?<br clear="all">
<br>Alex Bluesummers | <a href="http://www.MrBluesummers.com"><a href="http://www.MrBluesummers.com">http://www.MrBluesummers.com</a></a><br>
</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>wp-pro mailing list</span><br><span><a href="mailto:wp-pro@lists.automattic.com">wp-pro@lists.automattic.com</a></span><br><span><a href="http://lists.automattic.com/mailman/listinfo/wp-pro">http://lists.automattic.com/mailman/listinfo/wp-pro</a></span><br></div></blockquote></div></body></html>