Let x be the oxidation number of P in Mg2P––2O7.
Since the overall charge on the compound is 0, the sum of oxidation states of all elements in it should be equal to 0.
Therefore, 2(2+)+2x+7(2−)=0
Hence, x=+5.
Thus, the oxidation number of P in Mg2P––2O7 is +5.