Function get_the_ID() doesn't return 404 and search pages

I have a large switch statement where I get all the pages using the function get_the_ID() but it doesn't work for 404 and search pages. This is my code:

global $page, $paged, $post;

$selectpage = get_the_ID();

switch ($selectpage) {
    case (is_single() || is_page()):
        break;

    //......

    case (is_category()):
        break;
    case (is_search()):
        break;
    default:
        break;
}

I can use an if statement instead of a switch, but a switch doesn't re-evaluates the conditions. Also, I can use an if statement out of the switch, like this:

if ( is_404() ) {

} elseif ( is_search() ) {

} else {

    switch ($variable) {
        case ():
        break;

    }
}

But I prefer to think there's a better function for that situation, a function that includes the 404 and search pages.

Topic get-the-id Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.