How can I manage the background image of a slider based on the featured image of a page?

For those who wondered the same thing as me, here is a solution:

I’ve got various references along the way to solve this so sorry for the lack of some links. Most of the solution don’t come from me, I merely picked some pieces and put it together.

I used Revolution Slider and OptionTree to create the slider and the front-end options for the client to use.

You’ll need two pieces of code on your “functions.php”:

//Function to get id based on slug/link
function get_attachment_id_from_src ($image_src) {
    global $wpdb;
    $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
    $id = $wpdb->get_var($query);
    return $id;
}

// Define Featured Image based on OptionTree Theme Options
function defineFeaturedImage () {
    wp_reset_query();

    if (is_page()) {
        $page_id = get_the_ID();

        $post_slug = get_post_field( 'post_name', get_post() );

        if (is_page("https://wordpress.stackexchange.com/")) {
            $optiontree_id = 'bg_home';

        } elseif (is_page('firstpage')) {
            $optiontree_id = 'bg_firstpage';

        }
    }

    $url_featured = ot_get_option( $optiontree_id );

    $featured_id = get_attachment_id_from_src( $url_featured );

    if (!empty($page_id) && !empty($featured_id)) {

        set_post_thumbnail( $page_id, $featured_id );

    }
}
add_action( 'pre_get_posts', 'defineFeaturedImage', 10, 3);

After that you just need to configure OptionTree for the options like the ones above with the ID just like each page you need to change (you need to add more elseif to change more pages, this code you still need to add one at a time).
On Revolution Slider you need to configure the slider as any of the “Post Based” sliders type.

With that, revolution slider will change its background (if you set it to based on the post/page featured image), and even add any data from wordpress in the slider based on post/page.

So you just use this code above and OptionTree to control the featured image on each post/page.

Hope it helps someone 🙂