Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#29484 closed defect (bug) (invalid)

"posts_per_page" also restricts the number of images in a gallery

Reported by: avantart's profile Avantart Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.2
Component: Gallery Keywords:
Focuses: ui Cc:


When you define the number of posts on a page, f.e. the homepage, galleries in the posts also show only this number of images.
I use galleries with defined IDs.

For example: the gallery consists of 12 images, but the posts_per_page is set to 5 for the homepage in functions.php, so only the first 5 images are shown

posts_per_page should not have any impact on the number of images in a gallery

Check here:

you see 5 images in gallery

on single page you see 12 images:

the setting in the functions.php of my theme:

function custom_posts_per_page($query){

the gallery shortcode in the post:

[gallery link="file" columns="2" ids="25386,25387,25388,25389,25390,25391,25392,25393,25394,25395,25396,25397"]}}}

Change History (1)

#1 @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Yes, pre_get_posts runs for all queries.

To avoid unexpected results, you should make sure you're only changing the value for the main query on front-end, and return early otherwise:

if ( is_admin() || ! $query->is_main_query() ) {
Note: See TracTickets for help on using tickets.