WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#15962 closed defect (bug) (invalid)

Category 'posts_per_page' being ignored in query_posts when 'Blog pages show at most' set to 10

Reported by: tawilson Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.3
Component: Query Keywords:
Focuses: Cc:

Description

The scenario for this is as follows:

  • Using default category base.
  • In 'Appearance -> Reading', 'Blog pages show at most' is set to 10.
  • The permalink is accessing the category using it's slug name.
  • The category is using a custom 'category-slug.php'.

In the custom category, I have the following code, above the call to 'get_header()'.

global $wp_query;

query_posts(
		array_merge(
			$wp_query->query,
			array(
				'posts_per_page' => 2,
				'posts_per_archive_page' => 2
				)
			)
);

The first page shows 2 posts when the permalink is '/category/slug/'.

However, when the permalink is '/category/slug/page/2/', the query with the 'posts_per_page' set to 10, and as I only have 4 posts, it shows nothing.

If I set 'Blog shows at most' to something other than 10, it obeys my overridden value.

Change History (2)

comment:1 @SergeyBiryukov4 years ago

The request is parsed earlier, so the control doesn't even get to query_posts in this case.

You need to use query_string filter like in Ryan's example, or perhaps use a plugin like Different Posts Per Page.

comment:2 @nacin4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.