- This topic has 4 replies, 2 voices, and was last updated 1 year, 6 months ago by
Tom.
-
AuthorPosts
-
December 9, 2020 at 2:50 pm #1573599
Alexander
Hello,
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.
Thanks!
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 #1574699Tom
Lead DeveloperLead DeveloperHi there,
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?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 10, 2020 at 8:11 pm #1575239Alexander
Thanks, Tom.
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 towp_get_attachment_metdata($post->ID)
it’s working again as expected.Cheers
Alex.December 11, 2020 at 10:41 am #1576505Tom
Lead DeveloperLead DeveloperGlad you got it sorted 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.