First thing would be to see if is an external problem.
Common issue with Ford trucks is a loose column shifter cable(it doesn't "feel" loose), so gears don't get shifted correctly.
Google: ford ranger column shifter loose
Lots of videos and articles on this, same setup was used in all Ford trucks so it isn't Ranger specific.
Next would be the electric plug ins on the transmission, remove each one and check it for clean dry connectors and plug back in.
The TCC(torque converter clutch) lock/unlock solenoid connector could have intermittent connection.
Then have the Codes read at an auto parts store, it is free, WRITE any codes down, computer keeps track of transmission faults which don't always turn on the CEL(check engine light)