How to dedect if custom field contains a mp4 file in wordpress?
up vote
2
down vote
favorite
$video = get_post_meta($post->ID,'video_url', true); //default custom field
above is the custom field called video_url but its not allways a video format so I want to dedect first if its a video formar and Im using the following code:
$mimetypes = array('video/mov', 'video/flv', 'video/avi', 'video/avi', 'application/ogg', 'video/webm', 'video/mp4');
if (!empty($video) && in_array($video, $mimetypes) ) {
echo do_shortcode( $shortcode );
}
the shortcode will play it in html 5 video player.So when I remove && in_array($video, $mimetypes)
it plays fine but I want to dedect first if its a mp4 or not.
Is it possible to do it in wordpress?
Thankyou.
php wordpress custom-fields
add a comment |
up vote
2
down vote
favorite
$video = get_post_meta($post->ID,'video_url', true); //default custom field
above is the custom field called video_url but its not allways a video format so I want to dedect first if its a video formar and Im using the following code:
$mimetypes = array('video/mov', 'video/flv', 'video/avi', 'video/avi', 'application/ogg', 'video/webm', 'video/mp4');
if (!empty($video) && in_array($video, $mimetypes) ) {
echo do_shortcode( $shortcode );
}
the shortcode will play it in html 5 video player.So when I remove && in_array($video, $mimetypes)
it plays fine but I want to dedect first if its a mp4 or not.
Is it possible to do it in wordpress?
Thankyou.
php wordpress custom-fields
try to usestrpos()
or another php string search function
– Oleg Nurutdinov
yesterday
yes I have tried it too maybe I used in a wrong way but didn't work.
– Albano Albanese
yesterday
If your variable $video give a URL of a video then you can explode() funcion it with "." and find the file type from it and if mp4 is found then process your request thereafter.
– Mohammad Ashique Ali
yesterday
as I said above if I use onlyif (!empty($video) ) {
without the&& in_array($video, $mimetypes)
the video works fine but I have to dedect it first because of some other iframe codes given in the same metabox everything works fine the only thing is this..
– Albano Albanese
yesterday
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
$video = get_post_meta($post->ID,'video_url', true); //default custom field
above is the custom field called video_url but its not allways a video format so I want to dedect first if its a video formar and Im using the following code:
$mimetypes = array('video/mov', 'video/flv', 'video/avi', 'video/avi', 'application/ogg', 'video/webm', 'video/mp4');
if (!empty($video) && in_array($video, $mimetypes) ) {
echo do_shortcode( $shortcode );
}
the shortcode will play it in html 5 video player.So when I remove && in_array($video, $mimetypes)
it plays fine but I want to dedect first if its a mp4 or not.
Is it possible to do it in wordpress?
Thankyou.
php wordpress custom-fields
$video = get_post_meta($post->ID,'video_url', true); //default custom field
above is the custom field called video_url but its not allways a video format so I want to dedect first if its a video formar and Im using the following code:
$mimetypes = array('video/mov', 'video/flv', 'video/avi', 'video/avi', 'application/ogg', 'video/webm', 'video/mp4');
if (!empty($video) && in_array($video, $mimetypes) ) {
echo do_shortcode( $shortcode );
}
the shortcode will play it in html 5 video player.So when I remove && in_array($video, $mimetypes)
it plays fine but I want to dedect first if its a mp4 or not.
Is it possible to do it in wordpress?
Thankyou.
php wordpress custom-fields
php wordpress custom-fields
asked yesterday
Albano Albanese
537
537
try to usestrpos()
or another php string search function
– Oleg Nurutdinov
yesterday
yes I have tried it too maybe I used in a wrong way but didn't work.
– Albano Albanese
yesterday
If your variable $video give a URL of a video then you can explode() funcion it with "." and find the file type from it and if mp4 is found then process your request thereafter.
– Mohammad Ashique Ali
yesterday
as I said above if I use onlyif (!empty($video) ) {
without the&& in_array($video, $mimetypes)
the video works fine but I have to dedect it first because of some other iframe codes given in the same metabox everything works fine the only thing is this..
– Albano Albanese
yesterday
add a comment |
try to usestrpos()
or another php string search function
– Oleg Nurutdinov
yesterday
yes I have tried it too maybe I used in a wrong way but didn't work.
– Albano Albanese
yesterday
If your variable $video give a URL of a video then you can explode() funcion it with "." and find the file type from it and if mp4 is found then process your request thereafter.
– Mohammad Ashique Ali
yesterday
as I said above if I use onlyif (!empty($video) ) {
without the&& in_array($video, $mimetypes)
the video works fine but I have to dedect it first because of some other iframe codes given in the same metabox everything works fine the only thing is this..
– Albano Albanese
yesterday
try to use
strpos()
or another php string search function– Oleg Nurutdinov
yesterday
try to use
strpos()
or another php string search function– Oleg Nurutdinov
yesterday
yes I have tried it too maybe I used in a wrong way but didn't work.
– Albano Albanese
yesterday
yes I have tried it too maybe I used in a wrong way but didn't work.
– Albano Albanese
yesterday
If your variable $video give a URL of a video then you can explode() funcion it with "." and find the file type from it and if mp4 is found then process your request thereafter.
– Mohammad Ashique Ali
yesterday
If your variable $video give a URL of a video then you can explode() funcion it with "." and find the file type from it and if mp4 is found then process your request thereafter.
– Mohammad Ashique Ali
yesterday
as I said above if I use only
if (!empty($video) ) {
without the && in_array($video, $mimetypes)
the video works fine but I have to dedect it first because of some other iframe codes given in the same metabox everything works fine the only thing is this..– Albano Albanese
yesterday
as I said above if I use only
if (!empty($video) ) {
without the && in_array($video, $mimetypes)
the video works fine but I have to dedect it first because of some other iframe codes given in the same metabox everything works fine the only thing is this..– Albano Albanese
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Try to use strpos()
or another php string search function.
in_array()
doesn't works correct, cause, for example, your $video
looks like so:
www.site.com/videos/video.mp4
And you $mimetypes
array doesn't have this string inside
After that, your code will be so:
if (!empty($video) && strpos($video, 'mp4') !== false ) {
echo do_shortcode( $shortcode );
}
yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4
– Albano Albanese
yesterday
Warning: strpos(): needle is not a string or an integer in
– Albano Albanese
yesterday
check my edits.
– Oleg Nurutdinov
yesterday
wow :D is there any way to add multiple formats with commas?
– Albano Albanese
yesterday
thankyou very much everything is working fine I appreciate your help Oleg.
– Albano Albanese
yesterday
|
show 4 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Try to use strpos()
or another php string search function.
in_array()
doesn't works correct, cause, for example, your $video
looks like so:
www.site.com/videos/video.mp4
And you $mimetypes
array doesn't have this string inside
After that, your code will be so:
if (!empty($video) && strpos($video, 'mp4') !== false ) {
echo do_shortcode( $shortcode );
}
yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4
– Albano Albanese
yesterday
Warning: strpos(): needle is not a string or an integer in
– Albano Albanese
yesterday
check my edits.
– Oleg Nurutdinov
yesterday
wow :D is there any way to add multiple formats with commas?
– Albano Albanese
yesterday
thankyou very much everything is working fine I appreciate your help Oleg.
– Albano Albanese
yesterday
|
show 4 more comments
up vote
1
down vote
accepted
Try to use strpos()
or another php string search function.
in_array()
doesn't works correct, cause, for example, your $video
looks like so:
www.site.com/videos/video.mp4
And you $mimetypes
array doesn't have this string inside
After that, your code will be so:
if (!empty($video) && strpos($video, 'mp4') !== false ) {
echo do_shortcode( $shortcode );
}
yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4
– Albano Albanese
yesterday
Warning: strpos(): needle is not a string or an integer in
– Albano Albanese
yesterday
check my edits.
– Oleg Nurutdinov
yesterday
wow :D is there any way to add multiple formats with commas?
– Albano Albanese
yesterday
thankyou very much everything is working fine I appreciate your help Oleg.
– Albano Albanese
yesterday
|
show 4 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Try to use strpos()
or another php string search function.
in_array()
doesn't works correct, cause, for example, your $video
looks like so:
www.site.com/videos/video.mp4
And you $mimetypes
array doesn't have this string inside
After that, your code will be so:
if (!empty($video) && strpos($video, 'mp4') !== false ) {
echo do_shortcode( $shortcode );
}
Try to use strpos()
or another php string search function.
in_array()
doesn't works correct, cause, for example, your $video
looks like so:
www.site.com/videos/video.mp4
And you $mimetypes
array doesn't have this string inside
After that, your code will be so:
if (!empty($video) && strpos($video, 'mp4') !== false ) {
echo do_shortcode( $shortcode );
}
edited yesterday
answered yesterday
Oleg Nurutdinov
197113
197113
yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4
– Albano Albanese
yesterday
Warning: strpos(): needle is not a string or an integer in
– Albano Albanese
yesterday
check my edits.
– Oleg Nurutdinov
yesterday
wow :D is there any way to add multiple formats with commas?
– Albano Albanese
yesterday
thankyou very much everything is working fine I appreciate your help Oleg.
– Albano Albanese
yesterday
|
show 4 more comments
yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4
– Albano Albanese
yesterday
Warning: strpos(): needle is not a string or an integer in
– Albano Albanese
yesterday
check my edits.
– Oleg Nurutdinov
yesterday
wow :D is there any way to add multiple formats with commas?
– Albano Albanese
yesterday
thankyou very much everything is working fine I appreciate your help Oleg.
– Albano Albanese
yesterday
yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4
– Albano Albanese
yesterday
yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4
– Albano Albanese
yesterday
Warning: strpos(): needle is not a string or an integer in
– Albano Albanese
yesterday
Warning: strpos(): needle is not a string or an integer in
– Albano Albanese
yesterday
check my edits.
– Oleg Nurutdinov
yesterday
check my edits.
– Oleg Nurutdinov
yesterday
wow :D is there any way to add multiple formats with commas?
– Albano Albanese
yesterday
wow :D is there any way to add multiple formats with commas?
– Albano Albanese
yesterday
thankyou very much everything is working fine I appreciate your help Oleg.
– Albano Albanese
yesterday
thankyou very much everything is working fine I appreciate your help Oleg.
– Albano Albanese
yesterday
|
show 4 more comments
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372700%2fhow-to-dedect-if-custom-field-contains-a-mp4-file-in-wordpress%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
try to use
strpos()
or another php string search function– Oleg Nurutdinov
yesterday
yes I have tried it too maybe I used in a wrong way but didn't work.
– Albano Albanese
yesterday
If your variable $video give a URL of a video then you can explode() funcion it with "." and find the file type from it and if mp4 is found then process your request thereafter.
– Mohammad Ashique Ali
yesterday
as I said above if I use only
if (!empty($video) ) {
without the&& in_array($video, $mimetypes)
the video works fine but I have to dedect it first because of some other iframe codes given in the same metabox everything works fine the only thing is this..– Albano Albanese
yesterday