Using custom queries in Rev Slider

I have a rev slider that I want to use to display a custom post type of mine called vehicle. These vehicles have a meta field called “wpcm_featured” and its value can be either 0 for no or 1 for yes. I want my slider to display only featured vehicles and also to order them by price(wpcm_price) from low to high. The code I have now doesn’t seem to do any ordering or filtering except by post type.

function slider_hot_deals($query, $slider_id) {
    
    // only apply the special filter for slider with "x" ID
    // http://tinyurl.com/zb6hzpc
    if($slider_id == 4) {
        
        // order posts by vehicle price
        $query['meta_query'] = array(
            'price_clause' => 
                array(
                    'key' => 'wpcm_price',
                    'type' => 'numeric'
                ),
            'featured_clause' =>
                array(
                    'key' => 'wpcm_featured',
                    'type' => 'numeric',
                    'value' => '1'
                )
        );
        $query['orderby'] = 'price_clause';
        $query['order'] = 'ASC';
        
    }
    
    return $query;
    
}

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

What am I doing wrong?

Hi @justinlosh,

You can try this code instead.


function slider_hot_deals($query, $slider_id) {
    
    // only apply the special filter for slider with "x" ID
    // http://tinyurl.com/zb6hzpc
    if($slider_id == 4) {
        
        // order posts by vehicle price
        $query['meta_query'] = array(
            'price_clause' => 
                array(
                    'key' => 'wpcm_price',
                    'type' => 'numeric'
                ),
            'featured_clause' =>
                array(
                    'key' => 'wpcm_featured',                  
                    'value' => '1',
                    'compare' => '='
                )
        );
        $query['orderby'] = array('price_clause'=>'ASC');
       
    }
    
    return $query;
    
}

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

Please note that this is outside the scope of support as this is not related to an issue with the theme and instead has to do with your customization of it.

For more information, you may refer to the link below

https://codex.wordpress.org/Class_Reference/WP_Meta_Query

Thank you for your understanding.

Thanks that works.

You’re most welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.