Ecommerce Shopify WordPress Discussion

WordPress Custom Theme : I can't fetch my post video

I have some issues in my wp custom theme. I have to display my video attachment on my post, but i can't aime to get it. It's works on others pages but not in the following one : This is my where is my logic to fetch post videos : <?php if ( $post_id ) { $postId = intval($post_id); } else { $postId = intval(get_the_ID()); } $title = get_the_title($postId); $subtitle1 = get_post_meta($postId, 'cp_subtitle1', true); $subtitle2 = get_post_meta($postId, 'cp_subtitle2', true); $descriptive_date = get_post_meta($postId, 'cp_descriptive_date', true); $content = get_the_content($postId); $lang_code = get_post_meta($postId, 'cp_language_code', true); if ( empty($lang_code) ) { $lang_code = Lang::get_instance()->get_lang(); } $entryCat = get_category(get_post_meta($postId,'category2',true))->name; $post_date = get_post($postId)->post_date; $cpDate = new DateTime(); $cpDate->setTimestamp(strtotime($post_date)); $date = $cpDate->format('d F Y'); $banner = get_banner_by_postid($postId); $slider = get_slider_by_postid($postId); $default_thumb = ''; if ( has_post_thumbnail($postId) ) { $thumb = get_the_post_thumbnail_url( $postId, 'large'); }else if ( !empty($banner) ) { $thumb = $banner; } else { $thumb = get_stylesheet_directory_uri()."/assets/img/logo-PF.webp"; $default_thumb = 'default-thumb'; } if ( empty($banner) ) { $banner = $thumb; } /* * ALL ATTACHMENTS TYPE: APPLICATIONS */ $argsDocs = [ "post_type" => "attachment", 'post_mime_type' => 'application', 'post_parent' => $postId, "order" => 'ASC', 'posts_per_page' => -1, 'fields' => 'ids', ]; $attDocs = get_posts($argsDocs); /* * ALL ATTACHMENTS TYPE: IMAGES */ $argsImgs = [ "post_parent" => $postId, "post_type" => "attachment", "post_mime_type" => "image", "order" => 'ASC', 'posts_per_page' => -1, 'fields' => 'ids', ]; //$attImgs = get_posts($argsImgs); $attImgs = eppGetImages(array($postId), $argsImgs); /* * ALL ATTACHMENTS TYPE: VIDEOS */ $argsVideos = [ "post_parent" => $postId, "post_type" => "attachment", "post_mime_type" => "video", 'posts_per_page' => -1, ]; $attVideo = get_posts($argsVideos); if ( !empty($attVideo) ) { $vid_post_mime_type = $attVideo[0]->post_mime_type; $guidVal = $attVideo[0]->guid; $postTitle = $attVideo[0]->post_title; if ( $vid_post_mime_type == "video/x-vimeo" ) { $videoStr = explode("https://vimeo.com/" ,$guidVal)[1]; $iframeVidUrl = "https://player.vimeo.com/video/". $videoStr ; } elseif($vid_post_mime_type == "video/x-youtube") { $videoStr = explode("https://youtu.be/" ,$guidVal)[1]; $iframeVidUrl = "https://www.youtube.com/embed/". $videoStr; }elseif($vid_post_mime_type == "video/x-dailymotion") { $videoStr = explode("https://dai.ly/" ,$guidVal)[1]; $iframeVidUrl = "https://www.dailymotion.com/embed/video/". $videoStr; } if($vid_post_mime_type == "video/x-dailymotion") { $thumbUrl = "https://www.dailymotion.com/thumbnail/video/" . $videoStr; } else { $thumbUrl = 'https://vumbnail.com/'.$videoStr.'.jpg'; } } if ( empty($bgMediatheque) ) { $bgMediatheque = $banner; } $attDocId = []; $attImgId = []; $attMediaId = []; $attVidId = []; if ( count($attDocs) > 0 ) { foreach ($attDocs as $postAtt) { $attDocId[] = intval($postAtt); $attMediaId[] = intval($postAtt); } } if ( count($attImgs) > 0 ) { foreach ($attImgs as $postAtt) { $attImgId[] = intval($postAtt); $attMediaId[] = intval($postAtt); } } /**if ( count($attVideos) > 0 ) { foreach ($attVideos as $postAtt) { $vid_post_mime_type = $postAtt->post_mime_type; if ($vid_post_mime_type == "video/x-vimeo") { $attVidId[] = intval($postAtt->ID); } } }**/ $listDocEncode = base64_encode(implode('-', $attDocId)); $listImgEncode = base64_encode(implode('-', $attImgId)); $listMediaEncode = base64_encode(implode('-', $attMediaId)); $listVidEncode = base64_encode(implode('-', $attVidId)); $category1 = explode(',' ,get_post_meta($postId, "category", true)); $category2 = explode(',' ,get_post_meta($postId, "category2", true)); if ( count($category1) > 1 ) { $category1 = get_category(intval($category2[0])); } else { $category1 = get_category(intval(get_post_meta($postId, "category", true))); } $cat_brand = get_category($category1)->name; $cat_slug = get_category($category1)->slug; if ( $flux_marque == false ) { if ( getInfosBrand($cat_brand)['is-brand'] === true ) { $withBrand = true; } else { $entryCat = get_category(get_post_meta($postId,'category2',true))->name; if ( $flux_search == true ) { $entryCat = get_category($category1)->name; } } } if ( $withBrand == true ) { $category1 = explode(',' ,get_post_meta($postId, "category", true)); $category2 = explode(',' ,get_post_meta($postId, "category2", true)); if ( count($category1) > 1 ) { $category1 = get_category(intval($category2[0])); } else { $category1 = get_category(intval(get_post_meta($postId, "category", true))); } $cat_brand = get_category($category1)->name; $postCurrentMarque = getCurrentBrand($cat_brand); $logoMarque = get_slider_by_postid($postCurrentMarque->ID); $logoDefaultUrl = getImageBrand('logo-default', 'large', $postCurrentMarque->ID); if ( $default_thumb == 'default-thumb' ) { if ( !empty($logoDefaultUrl) ) { $thumb = $logoDefaultUrl; } else { $thumb = $logoMarque; } } } include('postObject_view/default_post_view.php'); ?> this is my single post page : <?php get_header(); if ( getInfosBrand($cat_brand)['is-brand'] == true ) { partial( 'head-marque' ); } else { partial( 'head' ); } ?> <!--END HEADER--> <div id="singlePF" class="single-<?php echo $cat_brand; ?> marque-<?php echo $cat_brand; ?>"> <div id="singlePF__header" <?php if ( empty($banner) ) { echo "class='no-banner'"; } ?>> <div id="singlePF__headerContent" class="single-header single-page-site <?php if ( is_single(['contacts-fra','contacts-eng']) ) { echo "contact-header"; } ?>"> <h1><?php echo $title; ?> </h1> <?php if ( !empty($subtitle1) ) { ?> <h2><?php echo $subtitle1; ?></h2> <?php } ?> <?php if ( !empty($contact) ) { ?> <div class="contact"><?php echo $contact; ?></div> <?php } ?> </div> <?php if ( !empty($banner) ) { ?> <img src="<?php echo $banner; ?>" alt="" /> <?php } ?> </div> <?php if ( !empty(strip_tags($content)) && strip_tags($content) !== 'Content' ) { ?> <div id="singlePF__content" class="bg-light-<?php echo $cat_brand; ?>"> <div class="entry-content"> <?php echo $content; ?> <?php if ( is_single(['politique-cookies-fr','politique-cookies-en']) ) { ?> <!-- OneTrust Cookies List start --> <div id="ot-sdk-cookie-policy"></div> <!-- OneTrust Cookies List end --> <?php } ?> <div class="post-video"> <?php if ( !empty($attVideo)) {?> <div> <?php var_dump($argsVideos); ?> <p>test</p> </div> <?php } else { ?> <p>pas de video</p> <?php } ?> </div> </div> </div> <?php } ?> </div> ?> <?php partial("structured_data"); get_footer(); ?> and this is where i can fetch my post video : get_header(); partial( 'head' ); $videoCorporatePostId = get_postid_by_slug('banner-corporate'); $argsBanner = array( "post_type" => ["post"], "post_status" => "publish", "orderby" => "date", "order" => "DESC", "meta_key" => "cp_language_code", "meta_value" => $lang, "tag" => "banner", "posts_per_page" => 1, ); $bannerPosts = get_posts($argsBanner); $bannerID = $bannerPosts[0]->ID; $argsVideos = [ "post_parent" => $videoCorporatePostId, "post_type" => "attachment", "post_mime_type" => "video", 'posts_per_page' => 1, ]; $attVideos = get_posts($argsVideos); if ( !empty($attVideos) ) { $vid_post_mime_type = $attVideos[0]->post_mime_type; $guidVal = $attVideos[0]->guid; $postTitle = $attVideos[0]->post_title; if ( $vid_post_mime_type == "video/x-vimeo" ) { $videoString = explode("https://vimeo.com/" ,$guidVal)[1]; $iframeUrl = "https://player.vimeo.com/video/". $videoString ; } elseif($vid_post_mime_type == "video/x-youtube") { $videoString = explode("https://youtu.be/" ,$guidVal)[1]; $iframeUrl = "https://www.youtube.com/embed/". $videoString; }elseif($vid_post_mime_type == "video/x-dailymotion") { $videoString = explode("https://dai.ly/" ,$guidVal)[1]; $iframeUrl = "https://www.dailymotion.com/embed/video/". $videoString; } if($vid_post_mime_type == "video/x-dailymotion") { $thumbUrl = "https://www.dailymotion.com/thumbnail/video/" . $videoString; } else { $thumbUrl = 'https://vumbnail.com/'.$videoString.'.jpg'; } } if ( empty($bgMediatheque) ) { $bgMediatheque = $bannerPosts; } ?> <div id="corpoMedicamentPF"> <div id="corpoMedicamentPF__banner"> <div id="marquePF__banner" > <?php ($bannerPosts); ?> <?php if ( !empty($bannerPosts) ) { ?> <div id="marquePF__banner" <?php if ( !empty($attVideos) ) { ?> class="have-play-button autoplay-video" <?php } ?> > <img class="banner" src="<?php echo esc_url($bannerPosts); ?>" /> <?php if ( !empty($attVideos) ) {?> <div class="play-button-container" data-video-id="<?php echo esc_attr($videoString); ?>" data-video-url="<?php echo esc_attr(esc_url($iframeUrl)); ?>" data-video-from="<?php echo esc_attr(substr($vid_post_mime_type, 8)); ?>" data-bg-video="true"> </div> <?php } ?> <div class="frame-container is-hidden"> </div> </div> <?php } ?> </div> </div> </div> I'm pretty new using custom template.. it will be very helpful to have some advices to know where i'm wrong :)
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.