Ticket #8179 (new defect (bug))

Opened 2 months ago

Last modified 2 months ago

query_posts + showposts + permalinks = 404

Reported by: wp_guy Assigned to: anonymous
Priority: normal Milestone: 2.8
Component: General Version: 2.7
Severity: major Keywords: query_posts, showposts, posts_per_page, permalink, 404
Cc:

Description

So, apparently when doing something like query_posts($query_string.'showposts=2'); in a category.php file for example. Everything seems to work fine, but the paging doesn't, I get 404 errors on the 3rd page.

Here is how the blog is setup:
- 'Blog pages show at most' is set to 5 in the settings
- category.php has a query_posts($query_string.'showposts=2');
- the category I'm browsing contains 7 posts.
- permalinks are set to 'month and name'

Here is what I do:
1. myblog.com/category/mycategory works fine, shows 2 posts
2. myblog.com/category/mycategory/page/2 works fine too, shows the next 2 posts
3. myblog.com/category/mycategory/page/3 returns a 404 error.

The above works just fine if I use the default permalink structure (query string).

I've seen this error in 2.6.3 and 2.7, haven't tried on earlier versions

Change History

11/12/08 17:42:34 changed by wp_guy

  • cc deleted.

(follow-up: ↓ 3 ) 11/12/08 18:14:27 changed by filosofo

I can't reproduce this. The following works fine:

$cat = get_query_var('cat');
query_posts("cat=$cat&showposts=2");

Are you sure that your $query_string variable consistently ends with an ampersand?

(in reply to: ↑ 2 ; follow-up: ↓ 4 ) 11/12/08 20:06:08 changed by wp_guy

I can't reproduce this.

Really? are you sure? have you tried going further back? I think it depends on the number of posts.

e.g.
7 posts: 1st page ok (posts 1 and 2) WP must somehow think it's showing 1-5,
2nd page ok (posts 3 and 4) WP must think it's showing 6-7,
3rd 404 error, I suppose because posts 10 to 15 don't exist (?)

if I add an error_log($GLOBALSwp_query?->query_varsposts_per_page?) I can see it go from '2' on the pages that work to '5' when I get the 404 error. Don't know if that matters.

There is a number of forum post on the matter. This one for example http://wordpress.org/support/topic/197628

Are you sure that your $query_string variable consistently ends with an ampersand?

I'm sure... I just forgot to add it when I submitted the ticket.

(in reply to: ↑ 3 ) 11/12/08 20:57:19 changed by filosofo

Replying to wp_guy:

I can't reproduce this.

Really? are you sure? have you tried going further back? I think it depends on the number of posts.

If I put the following in category.php, I can go back at least 10 pages (that's where I stopped).

 $cat = get_query_var('cat');
 $page = get_query_var('paged');
 query_posts("paged=$page&cat=$cat&showposts=2");

But that's on the latest trunk.