Hello wp-experts,
I've got a loop with search-results, containing posts, pages and attachments. In case i find an attachment, i'd like to permalink to the containing article - not to the attachment page.
After a little search in this forum, i tried this peace of code:
<?php if(get_post_type() == 'attachment') {
echo get_permalink()."<br />";
echo get_permalink($post->post_parent)."<br />";
$parent = get_post($post->post_parent);
echo get_permalink($parent->post_parent);
}
?>
But every line returns the same permalink: the link to the attachment-page.
Do you have an idea how to do this right?
Thanks in advance,
Alex