woocommerce offtopic – get embedded video url of products in functions

Any ideas on how to create a function that will pull all the embedded video urls of woocommerce products?

I tried it but it returns all the video attachments of the site.

add_action( 'init', 'echo_product_video_url' );
function echo_product_video_url() {
$all_urls = get_posts( array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'inherit',
'post_mime_type' => 'video/mp4'

) );
foreach ( $all_urls as $url ) {
echo '<pre>';
print_r($url);
echo '</pre>';
}
}

Any help would be much appreciated!

Leave a Comment