It sounds as if you are flying into Madrid and arriving on June 24th, then returning home (probably from Paris) in July, but do not have your transportation booked yet from Spain to Paris. Am I correct?
I'll first give you some transportation resources that may be helpful, in case you are not aware of them:
Rome2rio.com provides a broad look at all kinds of transportation available between two points. You can usually drill down and find links to the appropriate bus companies for the proposed routes. The cited trip durations and fares can be pretty inexact, but this will get you started and usually will highlight trips that will be tough slogs, information you may need in determining the most efficient routing through multiple stops. In Spain buses--which are quite comfortable--are often faster than trains when you're not traveling between major cities.
Skyscanner.com has schedules for flights within Europe. I'd recommend booking directly with your chosen airline, but only after carefully checking all the extra charges you may encounter and verifying that the airports to be used are actually located near your desired departure and arrival points.
Renfe is for train service, though locating schedules for the local trains can be tricky. You will not be able to find schedules for June/July yet, so just work with a date in February that falls on the same day of the week you expect to travel.
Because of the difficulty of locating local trains on the Renfe site, the Deutsche Bahn schedules can sometimes be very helpful.
You didn't say what you want to do in La Rioja (which is a region rather than a specific place), but I assume you have an interest in wine. I do not, and I haven't tried to visit wine-related sites anywhere in Europe, but I'm not sure how much you can accomplish in that rather rural area without a rental car. From the transportation standpoint I think La Rioja fits better with a visit to the Basque Country (Bilbao, San Sebastian, Vitoria-Gasteiz) than with trips to Madrid or Barcelona, so it does make sense to tackle La Rioja and San Sebastian on the same trip. The question is whether this is the trip. I don't believe you have time for this area as well as all I think you'll want to see in Andalucía. It would be a shame to go all the way to Andalucía and miss Granada, I think.
Although Rome2Rio does not know about it, there is regular bus service running between Vitoria-Gasteiz and Logroño, both of which have decent--though not particularly fast--transportation connections. One of the stops along the way is the utterly charming old hill town of Laguardia, which has a number of wine bars. I have only changed buses in Logrono, but I very much liked Vitoria-Gasteiz (which has a huge historic district) and Laguardia.
The schedule for buses between Vitoria-Gasteiz and Logroño is here. The first of the four charts is the summer schedule from V-G to Logroño. The third is the summer schedule from Logroño back to V-G. In each chart the top half is for Mon-Fri (non-holidays) and the lower half is for Sat/Sun/holidays.
There seem to be more flights out of Bilbao than out of San Sebastian, and the two cities are less than 90 minutes apart by bus, though the picturesque FEVE rail route is three times as long. I found just one non-stop flight to Paris from that area on July 9, departing from Bilbao at 2:50 PM.
Out of space. See next post.