Here is my code in my template file
$videoSC = '[vc_row][vc_column][td_block_video_youtube playlist_title="TITLE" playlist_yt="'.$vID.'"][/vc_column][/vc_row]';
echo do_shortcode($videoSC);
echo ($videoSC);
The last line is for debugging and outputs
[vc_row][vc_column][td_block_video_youtube playlist_title="TITLE" playlist_yt="Gb6JRborcOU,Xi0S2xKXSzg,ZGzup1LR9NU"][/vc_column][/vc_row]
When I plug that into a post, it views fine. However in the custom template, all I get is
<div class="vc_row wpb_row td-pb-row">
<div class="wpb_column vc_column_container td-pb-span12">
<div class="wpb_wrapper">
<div class="td_block_wrap td_block_video_playlist">
<div id="td_uid_11_56027c1641664" class="td_block_inner"></div>
</div> <!-- ./block_video_playlist -->
</div>
</div>
</div>
Please advise!
Is it the case that it only works upon a post submit and not when hard-coded in the template?
Is there anyway around this?
I found that there is a function being called when you add a post that parses the content and processes the shortcode
Managed to find it and it now works – here is my very specific solution
<h3>Videos</h3>
<?php
$videos = get_posts(array(
'post_type' => 'post',
'category' => 53,
'meta_query' => array(
array(
'key' => 'article_event', // name of custom field
'value' => '"'.get_the_ID().'"', // matches exaclty 123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
//echo get_the_ID();
if( $videos ):
$vID = '';
$vArray = array();
foreach( $videos as $video ):
$vID .= get_field( "article_video_id", $video->ID ) .',';
$vArray[] = get_field( "article_video_id", $video->ID );
endforeach;
endif;
$vID = rtrim($vID, ',');
function jj_get_video_info_data ($array_param){
$list_to_parse = $array_param;
$list_to_parse = explode(',', $list_to_parse);
$buffy = array();
//echo $list_to_parse;
foreach($list_to_parse as $id_video) {
$id_video = trim($id_video);//possible to have spaces
//echo '['.$id_video.']';
$response = wp_remote_get('https://www.googleapis.com/youtube/v3/videos?id=' . $id_video . '&part=id,contentDetails,snippet&key=AIzaSyBneuqXGHEXQiJlWUOv23_FA4CzpsHaS6I', array(
'sslverify' => false
));
if (is_wp_error($response)) {
break;
}
$data = wp_remote_retrieve_body($response);
if (is_wp_error($data)) {
break;
}
$obj = json_decode($data, true);
$buffy[$id_video]['thumb'] = td_global::$http_or_https . '://img.youtube.com/vi/' . $id_video . '/default.jpg';
$duration = $obj['items'][0]['contentDetails']['duration'];
if (!empty($duration)) {
preg_match('/(\d+)H/', $duration, $match);
$h = count($match) ? filter_var($match[0], FILTER_SANITIZE_NUMBER_INT) : 0;
preg_match('/(\d+)M/', $duration, $match);
$m = count($match) ? filter_var($match[0], FILTER_SANITIZE_NUMBER_INT) : 0;
preg_match('/(\d+)S/', $duration, $match);
$s = count($match) ? filter_var($match[0], FILTER_SANITIZE_NUMBER_INT) : 0;
$buffy[$id_video]['title'] = $obj['items'][0]['snippet']['title'];
$buffy[$id_video]['time'] = gmdate("H:i:s", intval($h * 3600 + $m * 60 + $s));
}
}
if(!empty($buffy)) {
return $buffy;
} else {
return;
}
}
$td_playlist_video['youtube_ids'] = jj_get_video_info_data($vID);
$td_playlist_video['youtube_title'] = 'Whatever';
//print_r($td_playlist_video);
update_post_meta(get_the_ID(),'td_playlist_video',$td_playlist_video);
$videoSC = '[vc_row][vc_column][td_block_video_youtube playlist_title="TITLE" playlist_yt="'.$vID.'"][/vc_column][/vc_row]';
echo do_shortcode($videoSC);
?>
Hi JanuszJasinski,
Thanks for sharing maybe it will help other users!