0

I am working on a function which pulls the length (in seconds) of the selected video in a custom post type, and puts this in a input.

I have come as far as this function:

value="<?php if ( isset ( $theme_stored_meta['background-video'] ) ) echo $theme_stored_meta['background-video'][0]; ?>"

This will put the URL to the video in the input box, if a video is selected. But how do I pull the length of the selected video from postmeta?

I have looked at the postmeta, and the part with the length looks like this:

s:6:"length";i:108;s:16:"length_formatted";s:4:"1:48";

But how do I pull the first length which is formatted in seconds and use it in my function? As you can see the "length" is what I want as that is in seconds, which I need.

Thank you!

EDIT:

This is how far I have come.

if( isset( $_POST[ 'background-video' ] ) ) {
   update_post_meta( $post_id, 'background-video-length', '22' );
}

Which will set the number 22 if a background-video is set in the post. But how do I get the length of the selected video instead of 22? Found this one, but I cannot use it, I cannot figure out how to use it at all:

$video_meta = get_post_meta( $attachment_ID, '_wp_attachment_metadata', true );
echo $video_meta['length_formatted'];

I don't know how I should target the correct attachment.

0

Function (here with samepl arguments) get_post_meta( $post_id, 'yout_meta_key', true); will automaitly transform serialzied data to array/object. If you accessing raw walue you will find function maybe_unserialzie usefull for deserialization.

  • But I don't know the $post_id, I just know the $theme_stored_meta['background-video'] which targets the uploaded/selected video attachment. – jockebq Apr 23 '18 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.