Calling wp_get_attachment_link with a non-existent ID throws PHP notice
|Reported by:||Jayjdk||Owned by:||ryan|
If you're are using the wp_get_attachment_link() function with a non-existent attachment ID, you'll get a notice.
<?php echo wp_get_attachment_link( 9 ); ?>
gives Notice: Trying to get property of non-object in C:\wamp\www\theme\wp-includes\post-template.php on line 1155
As far I can see, the code causing it is this (wp-includes\post-template.php on line 1155)
$_post = & get_post( $id ); if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) ) return __('Missing Attachment');
The $_post variable will be null in this case.
Change History (7)
comment:1 SergeyBiryukov — 2 years ago
- Keywords has-patch added; needs-patch removed
- Milestone changed from Awaiting Review to 3.3
- Owner set to ryan
- Resolution set to fixed
- Status changed from new to closed