Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionIn Wordpress, I am trying to check through an if else statement if the post is of a certain ID as follows:
<?php if ($post->ID == array(224,222,583,645,203,11,639,228,226,230,634,615,625,214,220,194)) : ?>
...do something...
<?php else : ?>
...do nothing...
<?php endif; ?>
This isn't working. Can you please help in knowing how to use the check the post ID in arrays?
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionIn Wordpress, I am trying to check through an if else statement if the post is of a certain ID as follows:
<?php if ($post->ID == array(224,222,583,645,203,11,639,228,226,230,634,615,625,214,220,194)) : ?>
...do something...
<?php else : ?>
...do nothing...
<?php endif; ?>
This isn't working. Can you please help in knowing how to use the check the post ID in arrays?
Share Improve this question asked Jun 13, 2019 at 8:07 Keyur AminKeyur Amin 31 silver badge4 bronze badges 3 |1 Answer
Reset to default 2As Sally highlights, you can use in_array() like this (untested):
// target ids
$ids = array(123, 321, 213);
if (!empty($post->ID) && is_numeric($post->ID) && in_array((int)$post->ID, $ids)) {
// do jazz
} else {
// do stuff
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745406080a4626320.html
in_array()
. – Sally CJ Commented Jun 13, 2019 at 8:16