Lord Vishnu has taken Varaha Avatar infinite times, if we consider cyclic nature of time, as many events repeat at regular intervals (may vary slightly sometimes). So, both stories are correct.
Lord Vishnu took Sweta Varaha (White Boar) incarnation at beginning of this Kalpa (hence the name Sweta Varaha Kalpa) to recover earth hidden in water and also to kill Hiranyâksha. This is how Srimad Bhagavatam describes this.
dvitiyam tu bhavayasya
yajnesah saukaram vapuh
The Creator said: 'When the Lord as the Unlimited One within the
universe for His pastimes assumed the form of the sum total of all
sacrifices [as the boar avatâra Varâha], He was determined to lift the
earth out of the great [Garbhodaka] ocean. In the ocean the first
demon [called Hiranyâksha, the 'demon of the gold'] appeared who by
Him was defeated with His tusk, like a thunderbolt piercing a pack of
In Chapter 15 Rudra Samhita (Sristi Khanda) of Shiva Mahapurana, Brahma explains the reason why Vishnu took Boar Avatar to find bottom of infinite Linga.
गमनेऽधो वराहस्य गतिर्भवति निश्चला।। धृतं वाराष्हरूपं हि विष्णुना
A boar can steadily go down deep below, therefore lord Visnu took to
the form of a wild boar.
अथवा भवकल्पार्थ तदूपं हि प्रकल्पितम्। विष्णुना च वराहस्य
Or in other words Visnu took to the form of a white boar in order to
यद्दिनं हि समारभ्य तद्रूपं धृतवान्हरिः। तद्दिनं प्रति कल्पोऽसौ कल्पो
The date from which Hari took to this form, Varaha-kalpa started from
तदिच्छा वा यदा जाता तस्य रूपस्य धारणे। तद्दिनं प्रति कल्पोऽसौ कल्पो
When he first desired to take to that Varaha form, since that time in
every (Maha)kalpa, the Varaha-kalpa was repeated.
Shiva Purana doesn't mention exactly when Lingodbhava occured. It might have happened in Sveta Kalpa as Shiva Purana mentions mainly events of Sveta kalpa. Lingodhbhava could have also happened during Agneya kalpa, as Linga Purana mentions mainly events of Agneya Kalpa, in addition to many other times.
So, both stories are true and these are just two Varaha Avatars among Vishnu's infinite Varaha Avatars.