1

I'm trying to show some specific text on top of the featured images depending on their IDs. Some of the featured images will have the same text.

$post_thumbnail_id = get_post_thumbnail_id();

if($post_thumbnail_id =='2030') {
echo '<span>Location</span>';
}

How do I check the array of $post_thumbnail_id?

The following example does not work.

if($post_thumbnail_id == array('1000','2000'))
  • 1
    Looking for in_array() ? – birgire Aug 1 '17 at 11:33
2

This is solely a PHP question. But as birgire mentioned, you can use in_array(). So, change your code to this:

$post_thumbnail_id = get_post_thumbnail_id();

if( in_array( $post_thumbnail_id, array(1, 2, 3 ) ) ) {
    echo '<span>Location</span>';
}

The first argument is your value, the second one is the array you want to search in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.