A preacher should always live by his own sermons. That's easier said than done though. Solomon was the writer of Proverbs 5:1-5, "My son, attend unto my wisdom... for the lips of a strange woman drop as an honeycomb... but her end is bitter... her feet go down to death; her steps take hold on hell." Solomon was wise enough to warn others to stay away from "strange women" - wild women, that is. But, evidently he later figured that it was something that he could control in his own life. I Kings 11:1 says plainly that Solomon loved MANY of those strange women that he had warned the rest of us about. Actually, he only had a 1000 of them. A thousand!?
God had warned (in Deuteronomy 17:16-17) that Jewish kings should neither accumulate horses from Egypt, nor wives... from anywhere, but especially foreign ones; idolatrous ones. Again, Solomon was guilty of all the above. It is a heartbreaking story. His wives turned his heart away from God and that cost him everything. His kingdom was divided into 2 unequal sections between a man named Jeroboam and Solomon's foolish son, Rehoboam. One would think that we would all learn from Solomon's mistakes, right? And yet, how successful are you in resisting your "besetting sin" (Hebrews 12:1). It's a sad reality. Alexander Pope's phrase "to err is human" applies to all of us so precisely. Knowing WHAT to do and actually DOING it ... well, we all know by experience that those are 2 very different things. Thankfully, "to forgive is divine" is also very accurate.
Now, the effect was not immediate. I Kings 11:4 says that the king was old when he took up idolatry. It is likely that he had already written the Song of Songs and the Proverbs before his fall into sin. Ecclesiastes would likely have been written as a confession at the very end of his life (Ecclesiastes 12:13).