The counter you want to use is probably just counter(heading)
. Using a custom selector instead just creates a completely different counter which is not stepped automatically.
To get the number of a specific heading, you can then use the at
method of the counter as in
#let next-heading = query(selector(...)).first()
#let number = counter(heading).at(next-heading.location())