There’s a general convention in WordPress:
- functions prefixed with
the_
will echo a value - functions prefixed with
get_
orget_the_
will return a value
In your case you need to use get_sub_field()
instead of the_sub_field()
eg:
echo do_shortcode( get_sub_field( 'slideshare' ) );
The documentation on the ACF site is very comprehensive: http://www.advancedcustomfields.com/resources/functions/get_sub_field/
NOTE: In your example code you didn’t need any of the quotes, you could’ve just passed in the $slides
variable directly if you were using get_sub_field()