This is because elseif
doesn’t work the way you think it does. You’re trying to use it in a way that’s closer to a switch
statement or multiple if
statement`
This:
if (post_type_exists('videos')) {
// exclude from search results
$wp_post_types['videos']->exclude_from_search = true;
} elseif (post_type_exists('coordinator')) {
// exclude from search results
$wp_post_types['coordinator']->exclude_from_search = true;
}
Is the same as this:
if (post_type_exists('videos')) { // if videos exists
// exclude from search results
$wp_post_types['videos']->exclude_from_search = true;
} else { // if it does not exist
if (post_type_exists('coordinator')) {
// exclude from search results
$wp_post_types['coordinator']->exclude_from_search = true;
}
}
else if
just shortens things so that it’s more readable and takes less time to type. It’s called syntactic sugar.
If you want to check multiple things in a row, then you should use multiple if
statements in a row:
if ( condition1 is true ) {
// do a thing
}
if ( condition2 is true ) {
// do a thing
}