I've been taught that God doesn't hear the prayer of the unsaved, unless it is a prayer of repentance. However, James says in James 1: "If any of you lack wisdom, let him ask of God, who giveth to all men liberally and upbraideth not, and it shall be given him." Now, it doesn't say that God "giveth to the saved man liberally..." It says, "ALL." So how can we say that He doesn't hear the prayer of all men? How then can the unsaved man ask and receive?
Two possible answers, from the standpoint of those who might say God doesn’t answer the prayers of the unsaved. First, James says, “If any of YOU.” The “you” here is obviously Christians to whom he is writing. So he would only be telling Christians (saved people) to pray for wisdom.
The second possible answer, maybe related, is that while God “sends rain on the just and the unjust” (Matthew 5:45), (that is, he gives to all men) regardless of prayer, he answers the prayers of only the saved. The verse you asked about only says he gives liberally to all men, but doesn’t say he answers their prayers.
We know that God gives liberally, and not just to his saved ones. Certainly nobody could say that all in the United States are saved, yet God has given to even the sinners of this nation liberally. He does that even if they don’t pray to him. God clearly listened to the prayers of at least two unsaved men. Paul prayed for three days after he lost his sight in a vision of Jesus. (Acts 9:9-11) He wasn’t saved until after that three days, when a man came and told him to be immersed (baptized) to wash away his sins (Acts 22:16). The other man was a Roman soldier named Cornelius. He “prayed to God always.” (Acts 10:2) God answered his prayer by telling him to send for Peter, who taught him about Jesus and immersed Cornelius and those of his household. Now these may fall under that category of those who were praying prayers of repentance, but God certainly listened to them before they were saved.
Perhaps a better answer, though, would be that the question is based on a faulty premise. You have been taught that God doesn’t hear the prayer of the unsaved, except for the repentant. That may not be true. The main verse that would teach that is John 9:31. “Now we know that God heareth not sinners: but if any man be a worshipper of God, and doeth his will, him he heareth.” The man who said that was just repeating what he had been taught, but may not have been right, either. The other possible verse that teaches that is, “But your iniquities have separated between you and your God, and your sins have hid his face from you, that he will not hear.” (Isaiah 59:2) In that passage, though, he is speaking about a nation (Israel) that had become so wicked that God had no choice but to destroy them. The previous verse says that God has the ability to hear and save.
James later says that the “effectual, fervent prayer of a righteous man availeth much.” (James 5:16) This does not, however, address whether the prayer of an unrighteous man has any effect. It may just be that the prayer of a righteous man is more likely to be answered by God the way that man wants it to be. God, like many parents, is more likely to answer the pleadings of his own children. But many parents also give to those children who are not their own. They give less, but they give. It may be that God is the same way. His love for all men causes him to give to all, but especially those who are his special children, his saved ones. I find no scripture to say this, but I find none to say otherwise.