Seemingly complicated way of displaying page views
First I think that you need to reconcile your use of session vs. cookie.  In your answer you explain technically what is happening in your code, but not what the overall user experience requirement is.  You need to match your usage of cookies vs. sessions vs. HTML local storage (though not used here), which are all means to convey application state to what the actual user experience needs of the application are.

Does the cookie represent a default user preference?  If so, then should you be overriding it when the user passes parameters or otherwise changes mode setting in a session only context?

Why use session at all if you are always going to set a new "mode" cookie which overrides whatever is in session and there is not a session-specific override context?  Most likely you are propagating session ID by cookie anyway, so if user deletes cookies, you are going to lose state anyway.

If for example you remove session from the equation altogether, you may get something like:

$mode = 'wall';
if(!empty($_COOKIE['projects-sorting'])) {
    $mode = $_COOKIE['projects-sorting'];
}
if(!empty($_GET['mode'])) {
    $mode = $_GET['mode'];
}
if($mode !== $_COOKIE['projects-sorting']) {
    setcookie("projects-sorting", $mode, time() + (86400 * 30), "/");
}




You are doing nothing in code shown here to validate/sanitize the inputs. Both $_COOKIE and $_GET are use input and should be validated/sanitized accordingly before passing these values further into the application (or especially placing back into user cookie).

Maybe something as simple as validateMode() function.

function validateMode($array, $key) {
    if(empty($array[$key]) || !is_string($array[$key])) {
        return false;
    }
    switch($array[$key]) {
        case 'wall':
        case 'forum':
            return true;
        default:
            return false;
    }
}


And usage with my suggestion like:

$mode = 'wall';
if(validateMode($_COOKIE, 'projects-sorting')) {
    $mode = $_COOKIE['projects-sorting'];
}
if(validateMode($_GET, 'mode')) {
    $mode = $_GET['mode'];
}
if($mode !== $_COOKIE['projects-sorting']) {
    setcookie("projects-sorting", $mode, time() + (86400 * 30), "/");
}