Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1426950
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
}
本文标签: How to check if the postID is in an array
版权声明:本文标题:How to check if the postID is in an array? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745406080a2657256.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
in_array()
. – Sally CJ Commented Jun 13, 2019 at 8:16