• I’m trying to do a little sideblog, but I find that each post in the sidebar deducts from the total number of posts on the main page if it would normally show on the main page. I’d like to call query_posts(‘cat=-17’) and have the sidelog category not be queried at all, but all the posts there also belong to other categories.

    Is there a current way to exclude every post from that category?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Looking at the code, it doesn’t appear so. The code basically looks for the existance of a ‘-‘. If this exists, it generates a where clause in to form of ‘category_id != x ‘.

    Unfortunately, this will mean that posts which also belong to other categories are picked up as well. What should be done is an anti join – i.e. something like ‘where post2cat.category_id not in (select category_id from wp_categories where category_id = ‘x’)’

    However, MySQL versions before 4.1 don’t support the in operator which places limits on what can be relationally. The only workaround is to programatically exclude e.g. via !is_category() or reassign the posts to only a single category.

    I’m, of course, happy to be proved wrong.

    Thread Starter davedot

    (@davedot)

    Thanks for the response.

    I’m currently excluding the sideblog posts by using !is_category(), but since they are still being included in the default query_posts() I’m getting less than my desired (8) posts per page. I appreciate the explaination though.

    Upon further investigation, I find my host is using 4.0.23. I guess I’ll keep an eye open for any fixes, and in the meantime I’ll just make them single-category.

    hi davedot, i’ve implemented something similar to what you wanted. try it and see whether it works.

    <?php if (have_posts()) { ?>
    <?php if (is_home()) { ?>
    <?php query_posts("cat=-1"); ?>
    <?php while (have_posts()) : the_post(); ?>
    ...

    then for the sidebar, i’m using the customizable post listing plugin to display that category you are using, which in my code above, is cat 1. and the entries in the sidebar won’t “eat” into the numbers being displayed on the main content.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Is there a workaround for the query_posts(cat=-x) shortcomings?’ is closed to new replies.