- This topic has 4 replies, 2 voices, and was last updated 1 year, 6 months ago by Tom.
December 9, 2020 at 2:50 pm #1573599Alexander
with your previous help, I’ve added some bells & whistles to my attachment pages. Without getting into too much detail, this has stopped working and I’m scratching my head about what’s going on.
Here’s a part of the Hook Element:
<?php global $post; $photo_title = single_post_title('',false); $faa_url = get_post_meta( $post->ID, 'store_link', true ); $metadata = wp_get_attachment_metadata(); $photo_id = wp_basename($metadata['file'],'.jpg');
It appears that retrieving the $metadata via wp_get_attachment_metadata() isn’t working anymore – the $photo_id (which is the base filename of the image) is empty; here’s what this looks like now: https://www.alex-kunz.com/the-bluest-hour-solana-beach/tabletop-blue-solana-beach/
In this link similarly, the Hook Element that I was using to show the width and height of the photo in the footer also stopped working (the text now reads “This photo appears in The Bluest Hour, Solana Beach at × pixels” when it should be “This photo appears in The Bluest Hour, Solana Beach at WIDTH × HEIGHT pixels”).
<?php global $post; $metadata = wp_get_attachment_metadata(); printf( __( 'This photo appears in <b><a href="%4$s" title="View %5$s" rel="gallery">%6$s</a></b> at <a href="%1$s" title="Link to full-size image">%2$s × %3$s</a> pixels<br>', 'generatepress' ), esc_url( wp_get_attachment_url() ), $metadata['width'], $metadata['height'], esc_url( get_permalink( $post->post_parent ) ), esc_attr( strip_tags( get_the_title( $post->post_parent ) ) ), get_the_title( $post->post_parent ) );
This also relies on wp_get_attachment_metdata.
I have no idea what’s going on and would greatly appreciate your help.
Alex.December 9, 2020 at 3:09 pm #1573609Alexander
Did WordPress 5.6 perhaps change wp_get_attachment_metadata? I found this https://core.trac.wordpress.org/ticket/50679 but don’t understand what it means.December 10, 2020 at 10:30 am #1574699TomLead DeveloperLead Developer
I’m afraid I’m not sure – I haven’t followed the changes they’ve made there.
What’s the first snippet doing, exactly?
As for the second snippet, have you debugged the variables to make sure the width and height are coming through?December 10, 2020 at 8:11 pm #1575239Alexander
For whatever reason, the default for the ID (per https://developer.wordpress.org/reference/functions/wp_get_attachment_metadata/), doesn’t work anymore for
wp_get_attachment_metdata()in WordPress 5.6 – after I changed it to
wp_get_attachment_metdata($post->ID)it’s working again as expected.
Alex.December 11, 2020 at 10:41 am #1576505
- You must be logged in to reply to this topic.