Well, I didn't know that Ferdinand was in the line of succession to the Spanish throne, but the link between him and Spain is the following:
Prince Ferdinand Maria (Madrid 1884 - Madrid 1958) was the son of Prince Ludwig Ferdinand of Bavaria and Infanta Maria de la Paz of Spain. He was naturalized in Spain in 1905, renounced his Bavrian titles and rights to the Bavarian throne in 1914 and was given the title "Infant of Spain". His first wife was Maria Teresa of Spain, a daughter of King Alfonso XII and Archduchess Maria Christina. His descendents are all Infants of Spain.
Maybe that helps a bit.
Marie