Title: Bug Report: Infinite Scroll -&gt; pre_get_posts
Last modified: August 21, 2016

---

# Bug Report: Infinite Scroll -> pre_get_posts

 *  Resolved [Frumph](https://wordpress.org/support/users/frumph/)
 * (@frumph)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/bug-report-infinite-scroll-pre_get_posts/)
 * Problem:
 * The pre_get_posts is affecting the edit.php “is_main_query()” in the admin area.
   So whatever is set in the add_theme_support for posts_per_page modifies the is_main_query()
   everywhere including admin.
 * current:
 *     ```
       /**
       	 * Let's overwrite the default post_per_page setting to always display a fixed amount.
       	 *
       	 * @param object $query
       	 * @uses self::archive_supports_infinity, self::get_settings
       	 * @return null
       	 */
       	function posts_per_page_query( $query ) {
       		if ( self::archive_supports_infinity() && $query->is_main_query() )
       			$query->set( 'posts_per_page', self::get_settings()->posts_per_page );
       	}
       ```
   
 * Needs to be:
 *     ```
       /**
       	 * Let's overwrite the default post_per_page setting to always display a fixed amount.
       	 *
       	 * @param object $query
       	 * @uses self::archive_supports_infinity, self::get_settings
       	 * @return null
       	 */
       	function posts_per_page_query( $query ) {
       if (is_admin()) return $query;
       		if ( self::archive_supports_infinity() && $query->is_main_query() && $query->is_home())
       			$query->set( 'posts_per_page', self::get_settings()->posts_per_page );
       	}
       ```
   
 * Check to see if it’s filter is being run is_admin and return the normal $query
   if is. (alternatively) also check the $query->is_home() to make sure it’s only
   on the home page., could use is_front_page() there as well.
 * [http://wordpress.org/extend/plugins/jetpack/](http://wordpress.org/extend/plugins/jetpack/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [Sergey Biryukov](https://wordpress.org/support/users/sergeybiryukov/)
 * (@sergeybiryukov)
 * WordPress Dev
 * [13 years, 1 month ago](https://wordpress.org/support/topic/bug-report-infinite-scroll-pre_get_posts/#post-3654356)
 * Note that `pre_get_posts` is an action, not a filter. `$query` is passed by reference,
   so there’s no need to return it.
 * Although `add_action()` and `add_filter()` are essentially [the same thing](http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/plugin.php#L314),
   Jetpack should use `add_action()` for `posts_per_page_query()` to prevent the
   confusion:
    [http://plugins.trac.wordpress.org/browser/jetpack/tags/2.2.2/modules/infinite-scroll/infinity.php#L23](http://plugins.trac.wordpress.org/browser/jetpack/tags/2.2.2/modules/infinite-scroll/infinity.php#L23)
 * The correct solution here would be to just add `! is_admin()` to the condition:
 *     ```
       /**
        * Let's overwrite the default post_per_page setting to always display a fixed amount.
        *
        * @param object $query
        * @uses self::archive_supports_infinity, self::get_settings
        * @return null
        */
       function posts_per_page_query( $query ) {
       	if ( ! is_admin() && self::archive_supports_infinity() && $query->is_main_query() )
       		$query->set( 'posts_per_page', self::get_settings()->posts_per_page );
       }
       ```
   
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [13 years, 1 month ago](https://wordpress.org/support/topic/bug-report-infinite-scroll-pre_get_posts/#post-3654357)
 * Thank you both for the report.
 * I created a trac ticket ([#1696-plugins](http://plugins.trac.wordpress.org/ticket/1696))
   about the problem, and I will post again here once we get this fixed.
 *  Thread Starter [Frumph](https://wordpress.org/support/users/frumph/)
 * (@frumph)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/bug-report-infinite-scroll-pre_get_posts/#post-3654360)
 * is_main_query() is used other places other then !is_admin that you should not
   want to affect as well, you need to also add && $query->is_home() to target specifically
   the home page
 * ref: author pages uses is_main_query()
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [13 years, 1 month ago](https://wordpress.org/support/topic/bug-report-infinite-scroll-pre_get_posts/#post-3654379)
 * The ticket is now closed (see [r698115-plugins](http://plugins.trac.wordpress.org/changeset/698115)
   for the fix).
 * [@frumph](https://wordpress.org/support/users/frumph/) Since Infinite Scroll 
   can be used on Archive pages as well, you don’t want to limit `posts_per_page_query`
   to the home page only.
 *  Thread Starter [Frumph](https://wordpress.org/support/users/frumph/)
 * (@frumph)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/bug-report-infinite-scroll-pre_get_posts/#post-3654380)
 * “can” but people generally don’t because you don’t really have setup information
   for the archive pages in your documentation
 * [http://jetpack.me/support/infinite-scroll/](http://jetpack.me/support/infinite-scroll/)
 * no reference to ‘archive’ at all or even search
 * If the plugin modifies the posts_per_page on the is_archive pages and people 
   don’t want it or compensate for it, then you’re doing something wrong.
 *  Thread Starter [Frumph](https://wordpress.org/support/users/frumph/)
 * (@frumph)
 * [13 years ago](https://wordpress.org/support/topic/bug-report-infinite-scroll-pre_get_posts/#post-3654433)
 * Is there a flag to enable or disable their usage on the author / search / archive
   pages if the theme designer doesn’t want them? .. seriously don’t want it on 
   the author pages.
 *  Plugin Contributor [Erick Hitter](https://wordpress.org/support/users/ethitter/)
 * (@ethitter)
 * [13 years ago](https://wordpress.org/support/topic/bug-report-infinite-scroll-pre_get_posts/#post-3654442)
 * The function `archive_supports_infinity()` is used by Infinite Scroll to control
   which archives have IS enabled. That function contains a filter, `infinite_scroll_archive_supported`,
   that you can use to modify the default behaviour. Within the function that you
   attach to that filter, you can leverage the WordPress conditional tags to limit
   which archives have Infinite Scroll support.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Bug Report: Infinite Scroll -> pre_get_posts’ is closed to new replies.

 * ![](https://ps.w.org/jetpack/assets/icon.svg?rev=2819237)
 * [Jetpack - WP Security, Backup, Speed, & Growth](https://wordpress.org/plugins/jetpack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jetpack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jetpack/)
 * [Active Topics](https://wordpress.org/support/plugin/jetpack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jetpack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jetpack/reviews/)

 * 7 replies
 * 4 participants
 * Last reply from: [Erick Hitter](https://wordpress.org/support/users/ethitter/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/bug-report-infinite-scroll-pre_get_posts/#post-3654442)
 * Status: resolved