Skip Navigation

[Resolved] converted video

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user is using a 3rd party plugin to optimize uploaded videos. He he would like to display the optimized videos, not the original.

Solution:
This needs a custom shortcode that will get the URL of the converted video from the database. Check this reply https://toolset.com/forums/topic/converted-video/#post-1978535

This support ticket is created 3 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by JamesS2731 3 years, 1 month ago.

Assisted by: Jamal.

Author
Posts
#1978221

Display the converted video instead of the original

#1978535

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I ended up building another shortcode that returns directly the URL of the converted file, but it does not work inside the source tag, while it works alone. Check this screenshot hidden link

<video class="single-video" controls="" autoplay="">
  <source src='[converted-media-url]'>
</video>

[converted-media-url]

So, I tried to build another shortcode that produces the whole video tag, but it still does not work. So, I built another shortcode that uses the plugin's one rt_media. But it does not generate only the URL, it also generates the video player. The final code is:

function converted_media_player_func( $atts ) {
  global $post;
  
  $id = media_info_func( array() );
  
  return do_shortcode( '[rt_media attachment_id="' . $id . '"]' );
  
  return $results;
}
add_shortcode( 'converted-media-player', 'converted_media_player_func' );

function media_info_func( $atts ) {
  
    // Attributes
    $atts = shortcode_atts(
        array(
            'field' => 'wpcf-video-upload',
        ),
        $atts
    );
  
    global $post, $wpdb;
      
    $field = $atts['field'];
    $info = $atts['info'];
    
    $media_url = get_post_meta( $post->ID, $field );
      
    $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $media_url )); 
    $attachment_id = $attachment[0]; 
      
    return $attachment_id;
}
add_shortcode( 'types-media-id', 'media_info_func' );

And can be used like:

[converted-media-player]

The result is the plugin's video player: hidden link

Please note, that this is custom code, and is therefore out of the scope of the support forum. If you are not comfortable with programming, consider hiring a developer. We have a list of partners here https://toolset.com/contractors/

#1979145

Thank you Jamal, thats solved it! I've now got both the video and the link to the video.

Perfect. Many thanks for all the work you've put into this. It much appreciated!

Best regards
James

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.