Take the Train
Surprisingly enough, one can make it to Stanjel without their own transport. The train station is only 1km or so away. There are 6 trains per day leaving from Sezana (about 20 minutes) and 6 a day coming from Nova Gorica (40 minutes). You can come from Ljubljana fairly easily, by changing at Sezana.
There does appear to be a train service to the town, but I have no idea how far away the station is from the protected tourist town on the hill. The trains from Ljubljana are also very irregular, and take a long time, because you have to go via Sezana. It can take anything between two and four hours. If there are trains, then there are very likely buses too, and they may prove a better bet. You'd have to check at the station in Ljubljana. I'd recommend driving if you can, though.
Driving is probably the best way of getting to Stanjel, and the Kras region as a whole, and the view of the town as you arrive is excellent. Just be careful of the formidable Burja wind that blows through the valleys, as it will really give your car a buffeting, which isn't helpful on the winding snaking roads of the region!