WordPress.org

Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#8179 closed defect (bug) (worksforme)

query_posts + showposts + permalinks = 404

Reported by: wp_guy Owned by:
Milestone: Priority: normal
Severity: major Version: 2.7
Component: General Keywords:
Focuses: 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 (5)

#1 @wp_guy
13 years ago

  • Cc wes@… removed

#2 follow-up: @filosofo
13 years ago

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?

#3 in reply to: ↑ 2 ; follow-up: @wp_guy
13 years ago

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.

#4 in reply to: ↑ 3 @filosofo
13 years ago

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.

#5 @Denis-de-Bernardy
13 years ago

  • Keywords query_posts showposts posts_per_page permalink 404 removed
  • Milestone 2.8 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

please re-open with more details to reproduce

Note: See TracTickets for help on using tickets.