WordPress.org

Ready to get started?Download WordPress

Forums

Jetpack by WordPress.com
[resolved] Bug Report: Infinite Scroll -> pre_get_posts (8 posts)

  1. Frumph
    Member
    Posted 1 year ago #

    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/

  2. Sergey Biryukov
    WordPress Dev
    Posted 1 year ago #

    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, 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

    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 );
    }
  3. Jeremy Herve
    Happiness Engineer
    Plugin Author

    Posted 1 year ago #

    Thank you both for the report.

    I created a trac ticket (#1696-plugins) about the problem, and I will post again here once we get this fixed.

  4. Frumph
    Member
    Posted 1 year ago #

    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()

  5. Jeremy Herve
    Happiness Engineer
    Plugin Author

    Posted 1 year ago #

    The ticket is now closed (see r698115-plugins for the fix).

    @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.

  6. Frumph
    Member
    Posted 1 year ago #

    "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/

    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.

  7. Frumph
    Member
    Posted 1 year ago #

    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.

  8. Erick Hitter
    Member
    Plugin Author

    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic