• Resolved maxgx

    (@maxgx)


    hi Jetpack team,
    do you happen to know of any custom post ordering plugin that does work with your Infinite Scroll module?

    i’ve already tried 4 of them (Intuitive Custom Post Order, Simple Custom Post Order, GNA Post Order, Post Types Order) and all cause the very same problem: when loading up a second batch of posts, the ones from the first load are repeated.

    so rather than try all of the post ordering plugin in the WP repository looking for a compatible one, could you let us know (i’m not the only one having this issue, there are quite a few mentions of it on WP forums) if there’s no hope of finding one simply because all such plugins end up creating their own custom queries?

    or if you’d be so kind to come up with a solution, as having a post ordering plugin, after all, comes very handy indeed to us WP users?

    or alternatively if you can suggest of a fool-proof way to order posts without conflicting with your Infinite Scroll module?

    thanks a lot in advance

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

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

    (@jeherve)

    Jetpack Mechanic ??

    While I’m not familiar with any of those plugins, you should be able to use them, and then customize Infinite Scroll to support the custom query options used by that post ordering plugin.

    To customize Infinite Scroll, you can use the infinite_scroll_query_args filter, as explained here:
    https://www.ads-software.com/support/topic/jetpack-infinite-scroll-breaks-sort-order?replies=4&view=all

    Thread Starter maxgx

    (@maxgx)

    sorry for the somehow late reply.

    it’s not that easy, for me at least, to dig into such plugins’ code, as they also tend to handle taxonomies ordering too.

    anyway, i’ve tried the filter with the Intuitive Custom Post Order plugin. this, i think, is where the plugin intervenes in the frontend query:

    // get_posts()
    			if ( isset( $wp_query->query['suppress_filters'] ) ) {
    				if ( $wp_query->get( 'orderby' ) == 'date' )  $wp_query->set( 'orderby', 'menu_order' );
    				if ( $wp_query->get( 'order' ) == 'DESC' ) $wp_query->set( 'order', 'ASC' );
    			// WP_Query( contain main_query )
    			} else {
    				if ( !$wp_query->get( 'orderby' ) )  $wp_query->set( 'orderby', 'menu_order' );
    				if ( !$wp_query->get( 'order' ) ) $wp_query->set( 'order', 'ASC' );
    			}

    so i changed the filter on your link to 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'] = 'menu_order';
    
    	return $args;
    }
    add_filter( 'infinite_scroll_query_args', 'jetpack_infinite_scroll_query_args' );

    but i get duplicate posts as before.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    I think you might be running into this bug:
    https://github.com/Automattic/jetpack/issues/1135

    Could you try to change the priority where you hook into infinite_scroll_query_args, as suggested here, and post there if that helped?

    Let me know how it goes!

    Thread Starter maxgx

    (@maxgx)

    hi Jeremy, still no luck, and i also came across another conflict too.

    this is the script now:

    function jetpack_infinite_scroll_query_args( $args ) {
    	$args['order']   = 'ASC';
    	$args['orderby'] = 'menu_order';
    
    	return $args;
    }
    add_filter( 'infinite_scroll_query_args', 'jetpack_infinite_scroll_query_args', 100  );

    i tried priority 3, i tried priority 2000, same results.

    another conflict:
    i’m reporting this here for the moment, i’ll see to open a ticket apart, but just to let you know, activating the EU Cookie Law plugin disables the Infinite Scroll completely.

    you click on the button to load up the next badge, it runs the animation, then nothing happens, no new batch of posts appears.

    unfortunately, while we can do without the ordering plugin, european sites cannot do without one of this cookie plugin.

    i’ll see if there’s a solution, or an alternative plugin, otherwise i’m afraid it’ll be necessary to drop Infinite Scroll

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    i tried priority 3, i tried priority 2000, same results.

    Thanks for giving it a try. Unfortunately, at this point I can only recommend that you subscribe to the issue on GitHub, and we’ll keep you posted on any progress we make on that issue.

    activating the EU Cookie Law plugin disables the Infinite Scroll completely.

    you click on the button to load up the next badge, it runs the animation, then nothing happens, no new batch of posts appears.

    Could you check for Javascript errors on the page, as explained here:
    https://codex.www.ads-software.com/Using_Your_Browser_to_Diagnose_JavaScript_Errors

    Let me know what you find!

    Thread Starter maxgx

    (@maxgx)

    thanks Jeremy

    i’ve sorted the cookie plugin by installing Cookie Notice by dFactory

    Thread Starter maxgx

    (@maxgx)

    an update for those who may happen on this thread looking for a similar solution:

    i haven’t found a proper solution yet, but there are two plugins who cause less problems than the standard drag’n’drop ones: Post Types Order and Reorder Posts: they both cause only 1 post repetition on the new batch loaded after clicking on the button (my set up is with button click, not page scroll).

    i decided for Reorder Posts, as you can drag posts on the separate admin screen it provides and it’s auto save the order, whereby with Post Types Order you’d have to scroll to the bottom of the page and click on the ‘Save Order’ button.

    I used wrong account to post, please ignore, and refer to the below solution.

    • This reply was modified 8 years, 5 months ago by k2digital.

    I am using jetpack version 4.3.1. My fix is in the below, so far so good.

    add_filter( 'infinite_scroll_query_args', 'jetpack_infinite_scroll_query_args' );
    
    function jetpack_infinite_scroll_query_args( $args ) {
    	
        // Customize the ordering
        $args['orderby'] = 'meta_value_num';
        $args['meta_key'] = 'YOUR_META_KEY';
        $args['order'] = 'DESC';
    
        try{
        	// Get the start page, if the request is from 1st page, it will be 0,  and then no need to do decrement.
        	$startPage = intval($_POST['query_args']['paged']);
        	if($startPage != 0) $startPage--;
    
            // Adding $args is to avoid the people making infinite scrolling request in
            // non 1st page
        	$currentPage = ($args['paged'] + $startPage);
    
        }catch(Exception $x){
            // If error exists, I just use back the paged argument
        	$currentPage = $args['paged'];
        }
    
        // Using offset is used to override the paged args which will be used in WP_Query
        $args['offset'] = $args['posts_per_page'] * $currentPage;
        
        return $args;
    }

    If you will use infinite scroll for custom post type with meta_key ordering, you have to change the query params in ‘pre_get_posts’ hook too to make the post display consistent.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘is there any post ordering plugin that works with Infinite Scroll?’ is closed to new replies.