It is not known for certain when Wang Hui was born—although he was said to be in his 40s when Emperor Xuānzong (r. 846–859) was asking chancellors to find appropriate husbands for the princesses in the 850s, placing a loose timeframe on the time of his birth.
[1][2] His family was from Jingzhao Municipality (京兆, i.e., the region of the Tang dynasty capital Chang'an) and claimed ancestry from Wei Wuji (魏無忌) the Lord of Xinling, a famous prince of the Warring States period state Wei, explaining that the line eventually changed its surname to Wang because it was from a house of kings (and Wang meant "king").
[1][4] At that time, Emperor Xuānzong, who was looking for appropriate husbands for his daughters, asked the chancellors to look among the officials who had passed the Jinshi examination, and Wang's name was mentioned.
Wang, however, did not want to marry into the imperial family, and he met the chancellor Liu Zhuan to decline on the account of age, as he was already in his 40s, as well as poor health.
[1][5] Later, during the reign of Emperor Xuānzong's son Emperor Yizong, when the former chancellor Linghu Tao served successively as the military governor (Jiedushi) of Xuanwu (宣武, headquartered in modern Kaifeng, Henan) and then Huainan Circuit (淮南, headquartered in modern Yangzhou, Jiangsu), Wang served as Linghu's secretary.
[1] Later, when Gao Shi (高湜) oversaw the office of imperial censors (御史臺, Yushi Tai), he had Wang Hui recalled to Chang'an to serve as a supervising censor Shi Yushi Zhiza (侍御史知雜), as well as Zhifang Yuanwailang (職方員外郎), a low-level official at the ministry of civil service affairs (吏部, Libu).
Wang was later made Sifeng Langzhong (司封郎中), still a supervisory official at the office of civil service affairs, as well as the magistrate of Chang'an County (one of the two counties making up the capital), but as at that time, the ranks of imperial scholars (翰林學士, Hanlin Xueshi) was severely lacking, Xiao had him made an imperial scholar and also Zhifang Langzhong (職方郎中), also a supervisory official at the ministry of civil service affairs; Wang was also put in charge of drafting edicts.
Yet later, he was made chief imperial scholar (翰林學士承旨, Hanlin Xueshi Chengzhi) and deputy minister of census (戶部侍郎, Hubu Shilang).
The eunuch monitor of the army, Yang Fuguang wanted to invite the Shatuo rebel Li Keyong to join the Tang cause, and Wang Hui agreed with the proposal.
Wang Duo then issued an edict in Emperor Xizong's name pardoning Li Keyong and summoning him to join the Tang imperial cause.
[11] After Tang forces, with Li Keyong as a major contributor, defeated Huang and recaptured Chang'an early in 883, Wang, for his contribution, was made You Pushe (右僕射), one of the heads of the executive bureau.
The chancellors, rebuking Wang for not accepting the imperial largess, had him made the prefect of Ji Prefecture (集州, in modern Bazhong, Sichuan) and ordered him to report immediately.
[1] Immediately after, though, Tian provoked Wang Chongrong and Li Keyong into attacking Chang'an, and Emperor Xizong fled to Xingyuan (興元, in modern Hanzhong, Shaanxi).
After Tian's removal, Emperor Xizong sent an edict summoning Wang to serve as the minister of civil service affairs (吏部尚書) and creating him the Marquess of Langye.