I'm using the code below to first grab the post's attachments (if they're either a Word doc or pdf file), then echoing the url of said attachment. This works great on the first post on a page. However, on each subsequent post the same attachment url is echoed, even if that post doesn't have an attachment. How can I keep that from happening?
$args = array(
'post_type' => 'attachment',
'post_mime_type' => array('application/doc','application/pdf'),
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
foreach ($attachments as $attachment) {
echo '<a href="' . wp_get_attachment_url( $attachment->ID ) . '">Download Spec Sheet</a>';
echo '</div>';
}