Jetpack by WordPress.com
Jetpack Infinite Scroll Breaks Sort Order (4 posts)

  1. Eric
    Posted 2 years ago #

    On my taxonomy pages I like to sort posts into alphabetical order. However, Jetpack seems intent on using the actual order of elements in the query array regardless of my sorting. I have the following in my functions.php file:

    add_action( 'pre_get_posts', 'modify_taxonomy_sort_order' );
    function modify_taxonomy_sort_order( $query ) {
        if ( $query->is_tax() && $query->is_main_query() ) {
            $query->set( 'posts_per_page', '-1' );
            $query->set( 'orderby', 'title' );
            $query->set( 'order', 'asc' );

    Before enabling infinite scroll, this worked fine. After enabling infinite scroll, the posts come out unsorted.

    I would be happy enough just disabling infinite scroll on the pages that use this sorting (since I ask for them all anyway with the '-1'), but I know of no way to do this.

    I do know that this function is being called and the if statement is being evaluated as true.

    Any thoughts on how to get the sort order working or disable infinite scroll on certain pages?


  2. Eric
    Posted 2 years ago #

    I am working around this issue with an if statement around the add_action for now, so that infinite scrolling is not supported on pages where it misbehaves.

    if ( $GLOBALS['wp_query']->query['publications'] ||  $GLOBALS['wp_query']->query['pubtype'] ) {
        add_action( 'after_setup_theme', 'my_infinite_scroll_init' );

    This simply looks for the existence of these types in the query array object of wp_query, and if it finds them it skips the add_action.

    There must be a better way...

  3. Eric
    Posted 2 years ago #

    Oops, that workaround does not work because the $wp_query global has not yet been filled in.

    Still looking for a way to get infinite scroll to obey orderby.

  4. Richard Archambault
    Happiness Engineer
    Plugin Author

    Posted 2 years ago #

    Hi eceleste!

    Have a look at this filter, this might help you out:


    You'll need to use the infinite_scroll_query_args filter. So, for example, you can use something like this:

     * Sort all Infinite Scroll results alphabetically by post name
     * @param array $args
     * @filter infinite_scroll_query_args
     * @return array
    function jetpack_infinite_scroll_query_args( $args ) {
    	$args['order']   = 'ASC';
    	$args['orderby'] = 'name';
    	return $args;
    add_filter( 'infinite_scroll_query_args', 'jetpack_infinite_scroll_query_args' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Jetpack by WordPress.com
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic