Too often parts of the Bible are taken literally when in their context they are figurative.
It is necessary to look at these verses in context; in reference to this specific "teaching moment" we read (emphasis mine):
34 Jesus spoke all these things to the crowd in parables; he did not
say anything to them without using a parable. 35 So was fulfilled what
was spoken through the prophet:
“I will open my mouth in parables, I will utter things hidden
since the creation of the world.”
44 “The kingdom of heaven is like treasure hidden in a field. When
a man found it, he hid it again, and then in his joy went and sold all
he had and bought that field. 45 “Again, the kingdom of heaven is
like a merchant looking for fine pearls. 46 When he found one of great
value, he went away and sold everything he had and bought it.
51 “Have you understood all these things?” Jesus asked.
“Yes,” they replied.
52 He said to them, “Therefore every teacher of the law who has
become a disciple in the kingdom of heaven is like the owner of a
house who brings out of his storeroom new treasures as well as old.”
53 When Jesus had finished these parables, he moved on from there.
The primary point Jesus is making is that the Kingdom of God is so incredibly valuable it would be worth paying any price to obtain a place within it.
So, yes, this account is literally what Jesus taught, but no, he did not teach using a literal form on this occasion.