Support » Plugin: Jetpack - WP Security, Backup, Speed, & Growth » Jetpack Infinite Scroll and IS Filter

  • Resolved ibimcleod

    (@ibimcleod)


    I am using a Genesis Child theme (agency pro) and Jetpack’s Infinite Scroll.
    I created a custom query to re-order posts on an archive page (category: travel-photography) based on a custom field called “ColorCode”
    To implement Infinite Scroll along with the custom query I am using a filter hooked to IS query args.

    The result is:
    Archive page – Loads Content Properly as page 1
    On clicking “Load More”
    Infinite Scroll – Paged 1 – reloads content properly with this as page 1
    Infinite Scroll – Paged 2 – reloads content properly with this as page 2
    Infinite Scroll – Paged 3 – reloads content properly with this as page 3

    Has anyone found a way to prevent page 1 from duplicating?

    Here’s the code I’ve entered into my functions.php file:

    //*Jetpack Infinite Scroll
    //*__add a name to the content div
    add_filter( 'genesis_attr_content', 'custom_attributes_content' );
    function custom_attributes_content( $attributes ) {
             if ( is_archive() ) {
                  $attributes['id'] = 'main-content';
             }
                  return $attributes;
    }
    
    //*__function to enable infinite scroll and hook it to the after theme set up
    function custom_infinite_scroll() {
     add_theme_support( 'infinite-scroll', array(
              'type'           => 'click',
              'container'      => 'main-content',
              'posts_per_page' => 'true',
              'wrapper'        => 'infinity',
              'render'         => 'genesis_do_loop'
    
     ) );
    }
    
    add_action( 'after_setup_theme', 'custom_infinite_scroll' );
    
    //*__filter IS to orderby ColorCode
    function agency_infinite_scroll_query_args( $args ) {
    
    	$args['order']   = 'ASC';
    	$args['orderby'] = 'meta_value';
            $args['meta_key']= 'ColorCode' ;
            $args['category']= 'travel-photography'; 
    
    	return $args;
    
    }
    add_filter( 'infinite_scroll_query_args', 'agency_infinite_scroll_query_args' );

    The site page is http://www.hirutmcleod.com/category/travel-photography

    Any insight would be much appreciated. I’ve been driving myself crazy over this!

    https://wordpress.org/plugins/jetpack/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Could you post the code you used to create the custom loop, so I can try to reproduce?

    Thanks!

    Thread Starter ibimcleod

    (@ibimcleod)

    Hi,

    Here’s the code I used:

    //* Order travel photography photos by color
    function agency_colororder_posts($query) {
            if($query->is_main_query() && is_category('travel-photography')
    ){
                $query->set( 'orderby', 'meta_value' );
                $query->set( 'meta_key', 'ColorCode' );
                $query->set( 'order', 'ASC' );
    
        }
    }
    add_action( 'pre_get_posts', 'agency_colororder_posts' );

    Plugin Contributor Lance Willett

    (@lancewillett)

    Hi ibimcleod,
    Did you change something? Looking at http://www.hirutmcleod.com/category/travel-photography/ it looks to be working as expected now.

    Thread Starter ibimcleod

    (@ibimcleod)

    I removed the colorcode query from the main loop. so now it loads the first page of posts without the re-order and then all posts (including dups) in color code order.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Jetpack Infinite Scroll and IS Filter’ is closed to new replies.