How to dedect if custom field contains a mp4 file in wordpress?












2















$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
    Nov 19 '18 at 10:36











  • yes I have tried it too maybe I used in a wrong way but didn't work.

    – Albano Albanese
    Nov 19 '18 at 10:37











  • 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
    Nov 19 '18 at 10:38











  • 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
    Nov 19 '18 at 10:39


















2















$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
    Nov 19 '18 at 10:36











  • yes I have tried it too maybe I used in a wrong way but didn't work.

    – Albano Albanese
    Nov 19 '18 at 10:37











  • 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
    Nov 19 '18 at 10:38











  • 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
    Nov 19 '18 at 10:39
















2












2








2








$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 Nov 19 '18 at 10:33









Albano AlbaneseAlbano Albanese

537




537













  • try to use strpos() or another php string search function

    – Oleg Nurutdinov
    Nov 19 '18 at 10:36











  • yes I have tried it too maybe I used in a wrong way but didn't work.

    – Albano Albanese
    Nov 19 '18 at 10:37











  • 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
    Nov 19 '18 at 10:38











  • 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
    Nov 19 '18 at 10:39





















  • try to use strpos() or another php string search function

    – Oleg Nurutdinov
    Nov 19 '18 at 10:36











  • yes I have tried it too maybe I used in a wrong way but didn't work.

    – Albano Albanese
    Nov 19 '18 at 10:37











  • 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
    Nov 19 '18 at 10:38











  • 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
    Nov 19 '18 at 10:39



















try to use strpos() or another php string search function

– Oleg Nurutdinov
Nov 19 '18 at 10:36





try to use strpos() or another php string search function

– Oleg Nurutdinov
Nov 19 '18 at 10:36













yes I have tried it too maybe I used in a wrong way but didn't work.

– Albano Albanese
Nov 19 '18 at 10:37





yes I have tried it too maybe I used in a wrong way but didn't work.

– Albano Albanese
Nov 19 '18 at 10:37













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
Nov 19 '18 at 10:38





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
Nov 19 '18 at 10:38













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
Nov 19 '18 at 10:39







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
Nov 19 '18 at 10:39














1 Answer
1






active

oldest

votes


















1














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
    Nov 19 '18 at 10:40













  • Warning: strpos(): needle is not a string or an integer in

    – Albano Albanese
    Nov 19 '18 at 10:41











  • check my edits.

    – Oleg Nurutdinov
    Nov 19 '18 at 10:43











  • wow :D is there any way to add multiple formats with commas?

    – Albano Albanese
    Nov 19 '18 at 10:44











  • thankyou very much everything is working fine I appreciate your help Oleg.

    – Albano Albanese
    Nov 19 '18 at 10:45











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',
autoActivateHeartbeat: false,
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









1














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
    Nov 19 '18 at 10:40













  • Warning: strpos(): needle is not a string or an integer in

    – Albano Albanese
    Nov 19 '18 at 10:41











  • check my edits.

    – Oleg Nurutdinov
    Nov 19 '18 at 10:43











  • wow :D is there any way to add multiple formats with commas?

    – Albano Albanese
    Nov 19 '18 at 10:44











  • thankyou very much everything is working fine I appreciate your help Oleg.

    – Albano Albanese
    Nov 19 '18 at 10:45
















1














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
    Nov 19 '18 at 10:40













  • Warning: strpos(): needle is not a string or an integer in

    – Albano Albanese
    Nov 19 '18 at 10:41











  • check my edits.

    – Oleg Nurutdinov
    Nov 19 '18 at 10:43











  • wow :D is there any way to add multiple formats with commas?

    – Albano Albanese
    Nov 19 '18 at 10:44











  • thankyou very much everything is working fine I appreciate your help Oleg.

    – Albano Albanese
    Nov 19 '18 at 10:45














1












1








1







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 Nov 19 '18 at 10:42

























answered Nov 19 '18 at 10:40









Oleg NurutdinovOleg Nurutdinov

356213




356213













  • yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4

    – Albano Albanese
    Nov 19 '18 at 10:40













  • Warning: strpos(): needle is not a string or an integer in

    – Albano Albanese
    Nov 19 '18 at 10:41











  • check my edits.

    – Oleg Nurutdinov
    Nov 19 '18 at 10:43











  • wow :D is there any way to add multiple formats with commas?

    – Albano Albanese
    Nov 19 '18 at 10:44











  • thankyou very much everything is working fine I appreciate your help Oleg.

    – Albano Albanese
    Nov 19 '18 at 10:45



















  • yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4

    – Albano Albanese
    Nov 19 '18 at 10:40













  • Warning: strpos(): needle is not a string or an integer in

    – Albano Albanese
    Nov 19 '18 at 10:41











  • check my edits.

    – Oleg Nurutdinov
    Nov 19 '18 at 10:43











  • wow :D is there any way to add multiple formats with commas?

    – Albano Albanese
    Nov 19 '18 at 10:44











  • thankyou very much everything is working fine I appreciate your help Oleg.

    – Albano Albanese
    Nov 19 '18 at 10:45

















yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4

– Albano Albanese
Nov 19 '18 at 10:40







yes exactly it can be an external or internal video like that. techslides.com/demos/sample-videos/small.mp4

– Albano Albanese
Nov 19 '18 at 10:40















Warning: strpos(): needle is not a string or an integer in

– Albano Albanese
Nov 19 '18 at 10:41





Warning: strpos(): needle is not a string or an integer in

– Albano Albanese
Nov 19 '18 at 10:41













check my edits.

– Oleg Nurutdinov
Nov 19 '18 at 10:43





check my edits.

– Oleg Nurutdinov
Nov 19 '18 at 10:43













wow :D is there any way to add multiple formats with commas?

– Albano Albanese
Nov 19 '18 at 10:44





wow :D is there any way to add multiple formats with commas?

– Albano Albanese
Nov 19 '18 at 10:44













thankyou very much everything is working fine I appreciate your help Oleg.

– Albano Albanese
Nov 19 '18 at 10:45





thankyou very much everything is working fine I appreciate your help Oleg.

– Albano Albanese
Nov 19 '18 at 10:45


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




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

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)