Problem with post__in
-
Hi, I’m having a strange problem with post__in. I am trying to create two new loops on a page, one to display sticky posts of class ‘events’, the other to display non-sticky ‘events’. This is what I’ve got:
// first create my query and object for sticky events $querySticky = array( 'category_name' => 'events', 'posts_per_page' => '20', 'meta_key' => '_EventStartDate', 'meta_compare' => '>=', 'meta_value' => $currentTime, 'orderby' => 'meta_value', 'order' => 'ASC', 'post__in' => get_option('sticky_posts') ); $queryStickyObject = new WP_Query($querySticky); // now create non-sticky query and object $queryNonSticky = array( 'category_name' => 'events', 'posts_per_page' => '20', 'meta_key' => '_EventStartDate', 'meta_compare' => '>=', 'meta_value' => $currentTime, 'orderby' => 'meta_value', 'order' => 'ASC', 'post__not_in' => get_option('sticky_posts') ); $queryNonStickyObject = new WP_Query($queryNonSticky); // check if there are any events to display if (($queryStickyObject->have_posts()) || ($queryNonStickyObject->have_posts())) { ?><h2 id="events-header"><a name="events" id="events">Upcoming Events</a></h2> <?php // display sticky event posts first while ($queryStickyObject->have_posts()) { $queryStickyObject->the_post(); if (is_sticky()) { echo 'it really is sticky, dummy!'; } ?><h3>first loop</h3><?php display_calendar_event(true); } // now display non sticky posts while ($queryNonStickyObject->have_posts()) { $queryNonStickyObject->the_post(); if (!(is_sticky())) { echo 'not sticky, dammit!'; } ?><h3>second loop</h3><?php display_calendar_event(false); } }If I have one or more sticky posts, it works fine. If all posts are sticky, it works fine, so the query constructed with ‘post__not_in’ => get_option(‘sticky_posts’) works fine. However, if I don’t have any sticky posts, the first query generates the set of non-sticky posts, and the first loop duly displays them, so I get them twice. I can easily fix this with a fudge, but I’d really like to know what is going on!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Problem with post__in’ is closed to new replies.