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.










share|improve this question






















  • 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

















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.










share|improve this question






















  • 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















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.










share|improve this question













$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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









Albano Albanese

537




537












  • 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




















  • 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


















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














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 );
}





share|improve this answer























  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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 );
}





share|improve this answer























  • 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















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 );
}





share|improve this answer























  • 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













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 );
}





share|improve this answer














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 );
}






share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$