I have no idea by looking at your code what it should be doing, but just guessing…
post_name = '$current_ref'
are you sure that both of them have the same “post_name”
and
LIMIT 1
If they are the same name this will limit the query to only getting 1 result.