About 6-7 million. This is about one elected official at any level globally per 1000 people.
There are approximately 45,930 members of national parliaments (the vast majority of whom are elected), plus a number of the order of 70 national elected officials (mostly Presidents) who are not members of national parliaments. So, there are approximately 46,000 national elected officials. More than 99% of elected officials globally are elected to subnational offices.
According to this source (citing a United Nations economic development database): "Data from 133 countries shows that women constitute 2.18 million (36 per cent) of elected members in local deliberative bodies."
This implies that there are about 6.06 million local elected officials in those 133 countries. This omits about 50 countries recognized in the national parliament estimate, but most of the countries omitted are very small and so have very few local governments that tend to have few elected officials each, so the undercount by omitting those countries should be much smaller than the proportion of countries omitted. My estimate is that adjusting for the omitted 50 countries would add not more than about 1 million additional local elected officials (an average of about 20,000 for each country omitted).
It appears that this definition of "local government" includes all subnational elected officials, including officials who would be "state government" elected officials in the U.S. and Mexico and provincial government elected officials in Canada - governments that one might call immediate subnational elected officials.
To get an order of magnitude estimate of how many local government elected officials are immediate subnational elected officials, there would typically be about 100 people at that level of government, there are about 190 countries in the world, and there are on average on the order of ten such immediately subnational governments (i.e. directly below the national government) per country. So, a crude estimate of 190,000 such officials out of 6 million (about 3%), would be on the right order of magnitude for elected officials at this level.
Note that in determining this number, it isn't necessarily helpful to distinguish between "federal" and "unitary" government countries, because even many countries with "unitary" governments, e.g. Sweden, still have local elected officials at the subnational level. Similarly, even absolute monarchies, like Saudi Arabia, still have some elected officials at the local government level, so the distinction between democracies and non-democracies isn't very helpful for this purpose.
Also, there is often some lack of clarity over whether a body with elected officials is a private non-governmental organization (like a homeowner's association or a state or national non-profit with very broad membership) or is a government organization (like a business improvement district) whose members should be included in the total, so there is definitional uncertainty as well as the sheer difficulty of identifying every government.
Errors in measurement are likely to be few due to the availability of official sources if you look hard enough, but when there are problems, the magnitude of the errors are likely to be high. For example, if you exclude school boards, or small rural municipalities, from the total in the U.S. you get a big numerical adjustment, since there are many such local governments.
Sometimes it is possible for one person to hold more than one elected office at the same time. But this is sufficiently rare that the impact on the total number of elected politicians is negligible.