0

I am trying to implement infinite scrolling on my theme, in my site, some pages use the regular sorting, some use reverse sorting and some use custom loops, I would like to add infinite scrolling to all three.

Jetpack offers a way to modify the query arguments it uses by using a filter https://developer.jetpack.com/hooks/infinite_scroll_query_args/

/**
 * 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' );

But when I try to use the conditionals I usually use to specify different $args it doesn't work as expected. Here is an example of what my filter looks like.

function my_filters ($args) {
    if ( 6 == get_query_var('cat') {
        /** Some arguments here **/
    }
}

How would you add a specific filter based on the page you are at?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.