#18491 closed defect (bug) (fixed)
Calling wp_get_attachment_link with a non-existent ID throws PHP notice
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.3 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Warnings/Notices | Keywords: | has-patch |
Focuses: | Cc: |
Description
If you're are using the wp_get_attachment_link()
function with a non-existent attachment ID, you'll get a notice.
Example:
<?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.
Attachments (2)
Change History (7)
Note: See
TracTickets for help on using
tickets.
Nice! Just to confirm; the patch from Sergey fixes the error