Skip to content

Commit 6014ebb

Browse files
authored
Merge pull request #349 from cloudinary/fix/video-init-outsideloop
alternate approach
2 parents 1182288 + 41a4403 commit 6014ebb

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

php/media/class-video.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ public function player_enabled() {
9595
* Initialises the Cloudinary player if it's enabled and if video content is found.
9696
*/
9797
public function init_player() {
98-
9998
if ( isset( $this->config['video_player'] ) && 'cld' === $this->config['video_player'] && ! is_admin() ) {
99+
global $wp_query;
100+
$posts = $wp_query->get_posts();
100101
// Check content has a video to enqueue assets in correct location.
101-
while ( have_posts() ) {
102-
the_post();
102+
foreach ( $posts as $post ) {
103103
$has_video = $this->media->filter->get_video_shortcodes( get_the_content() );
104104
$video_tags = $this->media->filter->get_media_tags( get_the_content(), 'video' );
105105
if ( ! empty( $has_video ) || ! empty( $video_tags ) ) {
@@ -124,8 +124,6 @@ public function init_player() {
124124
break; // Exit since we determined that a video is present.
125125
}
126126
}
127-
// Reset wp_query.
128-
rewind_posts();
129127
}
130128
}
131129

0 commit comments

Comments
 (0)