I’m using the following code to enable an if/else statement.
<?php
$types = array('.pdf', '.doc', '.xls');
$filename = array(get_post_meta($post->ID, 'mjwlink-url', TRUE));
if(0 < count(array_intersect(array_map('strtolower', $filename), $types))) {
echo 'One';
} else {
echo var_dump($filename);
}?>
The problem I have is that get_post_meta always returns an array in the format even when $single is set to true
array(1) { [0]=> string(34) "http://www.crimeandjustice.org.uk/" }
Any help appreciated.
It always returns an array because you are executing the
get_post_meta
function within thearray
language construct. According to the WordPress Codexget_post_meta
will not return an array if the third param is set totrue
. Therefore, swap:to
Just out of curiosity, the logic within the
if
statement will only work on an array, if you remove thearray
construct yourif
statement will fail.