Skip to main content

[WP] Modifying order of posts in the slider

There is new_royalslider_posts_slider_query_args filter that allows filtering of query arguments.

For example:

If you want to modify existing WP_Query, for example set order by title:

// Add to your theme functions.php
function newrs_custom_query($args, $index) {
// $args is WP_Query arguments object.
// feel free to change it here
$args['orderby'] = 'title';

// $index is an ID of slider that you're modifying

return $args;
add_filter('new_royalslider_posts_slider_query_args', 'newrs_custom_query', 10, 2);

Refer to WordPress codex for the list of available arguments - . Also, useful code that contains list of all possible arguments -

If you want to run multiple post queries for one slider (or you need completely custom query):

Use new_rs_slides_filter. Example below will add posts with post_type=pages after your current slides:

function add_additional_posts_to_slider($slides, $options, $type) {
// $options['id'] is a slider index

$args = array(
'post_type' => 'page'
$query = new WP_Query($args);

$additiona_slides = (array)$query->posts;
if( is_array($additiona_slides) ) {
$slides = array_merge($slides, $additiona_slides);
return $slides; // slides is array of WP Post objects that will be displayed in slider
add_filter('new_rs_slides_filter', 'add_additional_posts_to_slider', 10, 3);


If the code that you added isn't working, make sure that slider isn't cached (set cache refresh time to 0 on RoyalSlider Settings page, or preview it in admin).