• Resolved Michael

    (@mike247allday)


    I’m outputting a custom post type into a 3-column grid that needs to leave One empty space for a different block of content.

    To achieve this, I’m using $query->set inside of a pre_get_posts function:

    function portfolio_posts( $query ) {
    if ( is_admin() || ! $query->is_main_query() )
        return;
    if (is_tax('portfolio_category', 'custom-web-design') ) {
        $query->set( 'posts_per_page', 8 );
        $query->set( 'orderby', 'menu_order');
        $query->set( 'order', 'ASC');
        return;
    }
    if (is_tax('portfolio_category', 'brand-identity') ) {
        $query->set( 'posts_per_page', 11 );
        $query->set( 'orderby', 'menu_order');
        $query->set( 'order', 'ASC');
        return;
        }
    }
    
    add_action( 'pre_get_posts', 'portfolio_posts', 11);

    I’m attempting to add a Load More button, so I’m using Jetpack’s Infinite Scroll plug-in.

    Infinite Scroll also uses pre_get_posts, with an add_action priority of 10, which is why I set mine to 11.

    Problem is, when I run the code, the Load More button doesn’t appear now ??

    Is there any way to solve this without touching the core files of Jetpack?

    Since I feel this particular question warrants some Stack Overflow Reputation points, here’s the link: https://stackoverflow.com/questions/33292748/jetpack-infinite-scroll-conflicting-with-theme-pre-get-posts-query-set

    https://www.ads-software.com/plugins/jetpack/

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

    (@jeherve)

    Jetpack Mechanic ??

    Thanks for the detailed report. I’ve tried to reproduce, but I’m not having any luck; Infinite Scroll seems to work in all my loops at the moment, even with your code in place and some test custom taxonomies with the names you’ve defined.

    Could you contact us via this form, and mention this thread?
    https://jetpack.me/contact-support/

    If we could get a copy of your theme, it might be easier to reproduce and understand what’s going on.

    Thanks!

    Thread Starter Michael

    (@mike247allday)

    Actually scraped the custom number, then I had an issue of duplicating the 1st “Load More…” set of posts, and that was fixed with a filter snippet I found somewhere. Here’s what my final code ended up looking like:

    // Sort Power Portfolio Post Type
    function portfolio_posts( $query ) {
        if ( is_admin() || ! $query->is_main_query() )
            return;
        if (is_tax('portfolio_category') ) {
            // $query->set( 'posts_per_page', 50);
            $query->set( 'orderby', 'menu_order');
            $query->set( 'order', 'ASC');
            return;
        }
    }
    add_action( 'pre_get_posts', 'portfolio_posts', 10);
    
    // Fixes duplicate first Load More Page
    function my_infinite_scroll_fix_paged( $args ) {
        $args['paged']++;
        return $args;
    }
    add_filter( 'infinite_scroll_query_args', 'my_infinite_scroll_fix_paged' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Jetpack Infinite Scroll Conflicting with Theme pre_get_posts $query->set’ is closed to new replies.