I found the solution:
Replace
if (!$url) $url = get_permalink($post->ID);
with
$post_id = get_the_ID(); $url = get_post_meta("$post_id", 'links_link_custom', true);
I found the solution:
Replace
if (!$url) $url = get_permalink($post->ID);
with
$post_id = get_the_ID(); $url = get_post_meta("$post_id", 'links_link_custom', true);