Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've encountered some issues on a clients site since upgrading to WP 3.1.2, and have this evening updated to version 3.1.3, only to find that the problems still persist.

http://www.harmonyreins.com.au

The website is for a local animal shelter, and each post represents a different animal that lives at the shelter. There are a number of categories that specifically relate to the type of animal, such as dogs, cats, horse as well as a "recently adopted" and an "old friends" category. Those last two categories were excluded from the full post list (under 'Meet The Gang' in the navigation) using the following code:

<?php query_posts($query_string . '&cat=-10,-12'); ?>

The upgrade to WordPress 3.1.2 (or the accompanying database update, I'm not sure which) made this code redundant, and the excluded posts began appearing in the 'Meet The Gang' section. I enquired about the issue on WordPress.org, and the following fix was suggested:

Chris,

Replace the following in your theme's index.php

<?php query_posts($query_string . '&cat=-10,-12'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

with

<?php query_posts('cat=-10,-12'); ?>
<?php if ( have_posts() ) : while  ( have_posts() ) : the_post(); ?>

and you should be good.

Unfortunately this resulted in another issue, displaying the posts from page one of the list on page two also (you can see what I mean if you go to the site). I've tried multiple pagination plugins with no success. Regardless of what page you're on, only the first ten animals are displayed.

My client has been really good regarding this issue, but it's been going on for weeks now, and I really need to get it solved. Hoping someone can help me out. :-)

share|improve this question
    
just checking: are you using global $query_string; before the query? alternatively, you could try: <?php query_posts('cat=-10,-12&paged='.get_query_var('paged')); ?> –  Michael May 26 '11 at 11:41
    
@Michael please add that as an answer so it can be voted on and/or accepted –  Rarst May 30 '11 at 20:00
    
@Rarst - thanks for reminding me. Done it. –  Michael May 30 '11 at 20:10
add comment

2 Answers

are you using global $query_string; before the query? so that the full line looks like:

<?php global $query_string; query_posts($query_string . '&cat=-10,-12'); ?> 

alternatively, you could try:

<?php query_posts('cat=-10,-12&paged='.get_query_var('paged')); ?>
share|improve this answer
add comment

Your query_posts() should also contain information about the page you are on, for example by passing the paged parameter.

But doing your own query_posts() with paging is a recipe for problems. WordPress already does a query for you, it's better to change this query. Otherwise it is possible that WordPress finds more or less posts than your query, which will mess up paging.

Can you explain how your Meet the gang page works? Is is a Page with a special template that loads the posts? Or do you work with a static front page and is this the posts page? I would hook into pre_get_posts and add the correct category part of the query there.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.