#18491 closed defect (bug) (fixed)
Calling wp_get_attachment_link with a non-existent ID throws PHP notice
| Reported by: | Jayjdk | Owned by: | ryan |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.3 |
| Component: | Warnings/Notices | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Nice! Just to confirm; the patch from Sergey fixes the error