[Resolved] wp_get_attachment_metadata stopped working?

Home Forums Support [Resolved] wp_get_attachment_metadata stopped working?

Home Forums Support wp_get_attachment_metadata stopped working?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #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 &times; %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.

    #1573609
    Alexander

    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.

    #1574699
    Tom
    Lead Developer
    Lead Developer

    Hi 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?

    #1575239
    Alexander

    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 to wp_get_attachment_metdata($post->ID) it’s working again as expected.

    Cheers
    Alex.

    #1576505
    Tom
    Lead Developer
    Lead Developer
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.