Sticky and random post query
Greetings all — hoping to get some help; I reckon I kind of know what the problem is, just can’t seem to solve it on my own.
I’m trying to query three total posts from the same category (and display some of their custom fields): the first spot must be filled by a sticky post (I only have one); the other two spots need to be randomly populated by other posts in the same category.
The query I’m using is as follows:
<?php $sticky=get_option('sticky_posts') ; query_posts('p=' . $sticky); query_posts(array( 'post__in' => get_option('sticky_posts'), ) . 'cat=3&showposts=2&orderby=rand'); ?>
So, this seems to mostly do as I want, but the “showposts=2” seems to be my tripping point: most of the time, the sticky post and two random posts will show (for THREE total, exactly as desired). But on the occasional query, only TWO posts will show: the sticky post plus a random. If I raise to showposts=3, sometimes I’ll get 3 total, sometimes I’ll get 4.
Any idea how to get it so that three posts reliably show, always with the sticky first and the rest random? Am I on the complete wrong track here? Any help GREATLY appreciated!!! Thanks —
- The topic ‘Sticky and random post query’ is closed to new replies.