Ascending order in Post Slider

kevinfung.imi's Avatar

kevinfung.imi

23 Apr, 2020 08:06 PM

I have set the order by "Date" for my Post Slider. But how do I change the order to Ascending instead of descending?

I assume it is to be set in the PHP but would you give me some advice on how?

Thanks!

  1. Support Staff 1 Posted by Dmytro Semenov on 24 Apr, 2020 04:47 PM

    Dmytro Semenov's Avatar

    Hello,

    yes, you'll need to use php filter http://help.dimsemenov.com/kb/wordpress-royalslider-advanced/wp-mod...

    function newrs_custom_query($args, $index) {
        $args['order'] = 'DESC';
        return $args;
    }
    add_filter('new_royalslider_posts_slider_query_args', 'newrs_custom_query', 10, 2);
    

    https://developer.wordpress.org/reference/classes/wp_query/#order-o...

  2. 2 Posted by kevinfung.imi on 23 Jan, 2022 08:30 PM

    kevinfung.imi's Avatar

    Hi Dmitry,

    I'm again trying to sort post by date in an ascending order in Royal Slider, but it is not working. I added exactly this to function.php :

    // royalslider Add ASC order
    function newrs_custom_query($args, $index) {
        $args['order'] = 'ASC';
        return $args;
    }
    add_filter('new_royalslider_posts_slider_query_args', 'newrs_custom_query', 3);

    The slider ID is 3. I cleared cache and go back to RS and there is no change. Sorry I'm not really a coder and don't fully understand php filter. I may need more instructions...

  3. Support Staff 3 Posted by Dmytro Semenov on 24 Jan, 2022 06:18 PM

    Dmytro Semenov's Avatar

    The code looks correct. It'll apply only on the frontend (when embedded on some page), are you testing on the actual website?

    You can try some other parameters just to test, for example:

    function newrs_custom_query($args, $index) {
        $args['posts_per_page'] = 3; // limit to 3 slides
        return $args;
    }
    add_filter('new_royalslider_posts_slider_query_args', 'newrs_custom_query', 3);
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac