What you are referring to are stale blocks. Orphaned blocks are one for which the previous (parent) hash field points to an unknown block or to a block not yet processed by the local node. Since Bitcoin Core follows headers first approach, block headers are downloaded and validated first before downloading the block data. As a result, full nodes will never receive blocks whose parents it doesn't know about. So with the current headers first approach an orphan block will not be downloaded by your Bitcoin Core node.
Now, coming to stale blocks. All blocks are stored on the disk in the blocks/blk*.dat
file. The block data that you receive from your peers, if it is valid, is stored forever in that directory. However, in order to receive stale blocks, you need to be online at the time when your peer broadcasted a block to you from different chain view. Peers will only broadcast those blocks that they view form the current active chain from their perspective. So using that command, you will only be able to retrieve the stale blocks that you received when you were online.
You can use the bitcoin-cli getchaintips
command to return information about all known tips in the block tree, including the main chain as well as other branches.