Reputation: 6485
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.
Upvotes: 1
Views: 3634
Reputation: 73292
It always returns an array because you are executing the get_post_meta
function within the array
language construct. According to the Wordpress Codex get_post_meta
will not return an array if the third param is set to true
. Therefore, swap:
$filename = array(get_post_meta($post->ID, 'mjwlink-url', true));
to
$filename = get_post_meta($post->ID, 'mjwlink-url', true);
Just out of curiosity, the logic within the if
statement will only work on an array, if you remove the array
construct your if
statement will fail.
Upvotes: 7