Abdullah, Jesus didn't lie. What is happening here is a mix up of words and meanings, but it's actually all very simple
Jesus spoke to all sorts of groups.. to large groups on mountain sides, in homes filled with people, in synogogues, in homes with friends, next to graves and in the middle of lakes with just his close friends around.
He said he never spoke in secret.. now this is different from private talk and there was a reason for it.
Jesus was the master story teller who usually spoke in parables to the crowds. He would say things like "The kingdom of God is like...." Jesus who was God and also man, as God understood concepts that man never could understand, and as man, put it into stories so to make it as understandable as possible to those who listened.
However, he also took his disciples aside after talking to the crowds and explained to them privately and in more detail what it was he meant in the stories/parables he had told the wider audience. There was nothing secret about this private talk, it was only clarification of what He had told the whole group.
His purpose with the disciples was to teach them all things, and then when he returned to the Father, the Holy Spirit would bring to them remembrance and understanding, everything Jesus had told them. They would be the ones, not Him, to carry the message of the Gospel to the world. He would die, resurrect and ascend to the Father, but they would carry His message to the world, so they had to know exactly what he meant as he talked. So, they went to private tuition classes you might say.
Now, to understand the Pharisees question and Jesus' response, you have to look at the context.
The verse you missed out in your quote was the one to follow the one you quoted... John 18:21.
Why question me? ask those who heard me, surely they know what I said."
You see, Jesus was being questioned about his teachings by the high priest. Jesus response was very important. If he had only spoken to his disciples in private, their charges that he was trying to raise an insurrection and cause problems would have been real ones. However, Jesus words were not just heard by his disciples and therefore perhaps falsified.. whole crowds in public places, even synogogues heard him speak.
Muslims constantly declare that we have no proof that any of Jesus's words were actually His, yet here is the best and clearest proof of all. All of Jesus' teachings had been taught publically and there was nothing about them that was secret and therefore a political risk. They were trying to trick him, so they could find a reason to crucify him. Notice in verse 14 what was behind all the questioning. Caiaphas the high priest had already decided it would be good if someone died for the people. (John 11:45-52) .. this follows the raising of Lazarus from the dead. The mary mentioned is Jesus's friend Mary, sister to Lazarus, the man who had died.
Therefore, many of the Jews who had come to visit Mary and had seen what Jesus did, put their faith in Him. But some of them went to the Pharisees and told them what Jesus had done. Then the Chief Priests and the Pharisees called a meeting of the Sanhedrin.
"What are we accomplishing"? they asked. "Here is this man peforming miraculous signs. If we let him go on like this, everyone will believe in Him and then the Romans will come and take away both our place and our nation.
Then one of them, named Caiaphas, who was high priest that year spoke up. "You know nothing at all! You do not realise that it is better for you that one man die for the people, than the whole nation perish?"
He did not say this on his own, but as high priest for that year, he prophesised that Jesus wold die for the Jewish nation, and not only for that nation, but also for the scattered children of God, to bring them together to make them one. So, from that day, they plotted to take his life."
You see, Jesus knew their questioning was an elaborate plot to trick him, so they could accuse him of treason. Jesus' quiet unassuming response, was if you really want to know what I am teaching.. go ask all the thousands who have listened to me. I dont talk in secret and they will agree with me and with each other about what I am saying to you."
There is a lot at stake in this passage.. it's not a case of Jesus lying, or Jesus misleading.. it's His credibility on the line, and he promised His life was an open book before them... and the people were the witnesses to it.