0

I have added this snippet to functions.php to be able to order Slider Revolution slides:

// orderby slideshows

function modify_slider_order($query, $slider_id) {

// only alter the order for slider with "x" ID
// https://tinyurl.com/zb6hzpc

if($slider_id == 17 ) {

    // Custom Meta key/name
    $query['meta_key'] = 'numeric_order';

    // Order by Custom Meta values
    $query['orderby'] = 'numeric_order';

    // Calculate order based on:
    // 'NUMERIC', 'CHAR', 'DATE', 'DATETIME', 'TIME'
    $query['meta_type'] = 'NUMERIC';

}


return $query;

}

add_filter('revslider_get_posts', 'modify_slider_order', 10, 2);

I would like to reference either all slideshows, or another (id=16). I have tried commenting out the "if($slider_id..." part, and also tried adding the other slide id separated by a comma next to the 17, but WP is kicking up errors. Thank you.

2 Answers 2

0

Well I figured out I could duplicate the function and rename the title so it runs twice. But for future, is there a more elegant way of doing this in one instance? thanks!

// orderby slideshows

function modify_slider_order($query, $slider_id) {

// only alter the order for slider with "x" ID
// https://tinyurl.com/zb6hzpc

if($slider_id == 17 ) {

    // Custom Meta key/name
    $query['meta_key'] = 'numeric_order';

    // Order by Custom Meta values
    $query['orderby'] = 'numeric_order';

    // Calculate order based on:
    // 'NUMERIC', 'CHAR', 'DATE', 'DATETIME', 'TIME'
    $query['meta_type'] = 'NUMERIC';

}


return $query;

}

add_filter('revslider_get_posts', 'modify_slider_order', 10, 2);

// orderby slideshows2

function modify_slider_order2($query, $slider_id) {

// only alter the order for slider with "x" ID
// https://tinyurl.com/zb6hzpc

if($slider_id == 16 ) {

    // Custom Meta key/name
    $query['meta_key'] = 'numeric_order';

    // Order by Custom Meta values
    $query['orderby'] = 'numeric_order';

    // Calculate order based on:
    // 'NUMERIC', 'CHAR', 'DATE', 'DATETIME', 'TIME'
    $query['meta_type'] = 'NUMERIC';

}


return $query;

}

add_filter('revslider_get_posts', 'modify_slider_order2', 10, 2);

0

Maybe a late reply, but you can achieve this by using Logical Operators (see https://www.php.net/manual/en/language.operators.logical.php for more information about this subject)

So let's change the if statement to add the second slider

// orderby slideshows
function modify_slider_order($query, $slider_id) {

    if($slider_id == 17 || $slider_id == 16 ) {

        // Custom Meta key/name
        $query['meta_key'] = 'numeric_order';

        // Order by Custom Meta values
        $query['orderby'] = 'numeric_order';

        // Calculate order based on:
        // 'NUMERIC', 'CHAR', 'DATE', 'DATETIME', 'TIME'
        $query['meta_type'] = 'NUMERIC';

    }

    return $query;

}
add_filter('revslider_get_posts', 'modify_slider_order', 10, 2);

See what we did there? || is a logical operator for OR. So the function will execute if the ID equals 17 or 16.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.