Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress Conditional Content by Multiple Post Types

working on a highly complex WordPress theme that features many different custom post types. I was under the impression that the following code would check to see if the current post was of the type "philosopher" and then run the PHP conditional that follows it only if the post is in that type:

<?php if (get_post_type() == 'philosopher') { ?>

Unfortunately, my expectation was that to make the same item conditional for "philosopher", "text", and "original" my code should look like this:

<?php if (get_post_type() == 'philosopher','text','original') { ?>

But alas, I was wrong. I did get the following code to work, but I'm wondering if there's a cleaner way to do this (or if I'm somehow missing something)

        <?php if ( (get_post_type() == 'philosimply') || (get_post_type() == 'text') || (get_post_type() == 'original'))  { ?>
like image 285
Brian Avatar asked Jun 06 '26 04:06

Brian


1 Answers

if ( in_array(get_post_type(), array('philosopher','text','original')) ){ ... }

http://www.php.net/manual/en/function.in-array.php

Is that, what you are looking for?

HTH

like image 68
Andreas Avatar answered Jun 07 '26 18:06

Andreas