It is not sufficient that the subscheme of poles and zeroes is defined together over $K$, as the example of the function $(z+i)/(z-i):\mathbb P^1 \to \mathbb P^1$, defined only over $\mathbb Q(i)$, illustrates.
If poles of $f$, which form together a subscheme $D_\infty$, are defined over $K$, then the line bundle $\mathcal O(D_\infty)$ is defined over $K$. $f$ can be defined as the section of this line bundle that has the most poles, so it should be defined over $K$ as well.
More formally, suppose $f$ is not defined over $K$ (where $K$ is a separable extension of base field, which is $\mathbb Q$ here anyway). Then for some element $\sigma$ of Galois group of base field $f$ and $\sigma f$ would be sections of $\mathcal O(D_\infty)$ that have the same poles and zeroes, so their ratio would be a holomorphic function on $X$, thus constant.
Therefore every $\sigma$ must act as a multiplication by constant. It remains to select any source point $x$ and divide the function by $f(x)$. After this, action of $\sigma$ will have to be multiplication by 1, thus a multiple of $f$ is defined over $K$ indeed.