Take a look at this example situation:

Last month Gary was in hospital for an operation.
Liz didn’t know this, so she didn’t go to visit him.
They met a few days ago.
LIZ: If I had known you were in hospital, I would have gone to visit you.
When Liz said If I had known…, she indicated that the real situation was that she didn’t know he was in hospital.

When you are talking about the past, you use if + had (‘d)…
(if I had known / been / done etc.)
• I didn’t see you when you passed me in the street.
If I’d seen you, of course I would have said hello.
(but I didn’t see you)
• I decided to stay at home last night.
I would have gone out if I hadn’t been so tired.
(but I was tired)
• If he had been looking where he was going,
he wouldn’t have walked into the wall.
(but he wasn’t looking)
• The view was wonderful.
If I’d had a camera, I would have taken some photographs.
(but I didn’t have a camera)

• I am not hungry. If I was hungry, I would eat something. (now)
• I wasn’t hungry. If I had been hungry, I would have eaten something. (past)
Do not use would in the if-part of the sentence.
We use would in the other part of the sentence.
  • If I had seen you, I would have said hello. (NOT   ‘If I would have seen you’)

Note that ‘d can be would or had.
• If I’d seen you… (I‘d seen = I had seen)
I’d have said hello. (I‘d have said = I would have said)
We use had (done) in the same way after wish.
wish something had happened = I am sorry that it didn’t happen.
  • I wish I’d known that Gary was ill.
I would have gone to see him. (but I didn’t know)
• I feel sick. I wish I hadn’t eaten so much cake.
(but, unfortunately, I ate too much cake)
• Do you wish you had studied science instead of languages?
(you didn’t study science)
• The weather was cold while we were away. I wish it had been warmer.

Do not use would have… after wish in these sentences:
• I wish it had been warmer. (NOT   ‘I wish it would have been’)

Compare would (do) and would have (done).
  • If I had gone to the party last night, I would be tired now. (I am not tired now – present)
• If I had gone to the party last night, I would have met lots of people. (I didn’t meet lots of people – past)
Compare would have, could have and might have.

• If the weather hadn’t been so bad, { we would have gone out.
we could have gone out.
(= we would have been able to go out)
we might have gone out.
(= perhaps we would have gone out)