[wp-hackers] 2.1: Alternative to query_posts?

Joefish joefish.hackers at feastofcrumbs.com
Wed Jan 10 18:21:39 GMT 2007

Not long ago I set up a template-based alternative to Owen's Adhesive
plugin (which has been a little troublesome for me).

I set a category for sticky posts, hid that category in the sidebar
with exclude= and set home.php to use two loops, one for only the
sticky post category, and one for everything but the sticky post
category. I set up each loop with query_posts like this:

<?php if (!is_paged()) { query_posts('cat=48'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      loop for category 48, sticky posts
<?php endwhile; endif; ?>

<?php query_posts('cat=-48'); ?><?php } ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      loop for everything else
<?php endwhile; endif; ?>

The if (!is_paged()) bit is to keep the custom queries on the front page only.

This was working great for me with 2.0.x, but with 2.1 beta 1 and beta
2, it only works when category 48 is not empty, i.e., when I have a
sticky post. In 2.0.x, if the category is empty, the if (have_posts())
bit would return false and the first loop would have no output. But
with 2.1, the query returns an SQL error and dies.

Is this a bug in 2.1, or should I be setting up the loop in some other way?

More information about the wp-hackers mailing list