• Hi good evening everyone one,
    How do I make wordpress read the Album artist id3 tag, by default wordpress reads the Title, Artist and Album only.

    I tried this code below but it didn’t work.

    
    // Add id3 tags as meta keys
    add_filter( 'wp_get_attachment_id3_keys', $callback_id3 = function( $fields ) 
    {
        $fields['Album Artist'] = 'Album Artist';
        return $fields;
    } );
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    I think the space in the key name is messing things up. With key name 'album-artist' your code works for me. This allows you to save and edit the field in attachment meta data, but it doesn’t affect the actual id3 data embedded in the file. It also will not read any such data embedded in the file. The WP functions that read the embedded data do not have any filters from which we can enhance what they do. You’d have to invoke your own data extraction process when the file is uploaded.

    Thread Starter Epiphany

    (@epiphany1)

    Thank you very much for replying, I saw the code above on WordPress Stackexchange he used it to retrieve “Comments and Title id3” tags.

    If can’t read the “Album Artist ID3 tag” give me a clue on how to read the “Album Artist Tag”

    I tried adding the code below to media.php in my localhost but it didn’t work.

    if ( ! empty( $data['album-artist'] ) ) {
            $metadata['album-artist'] = $data['album-artist'];
        }
    
    Moderator bcworkz

    (@bcworkz)

    WP does not even try to get the album artist field from the file. You’d need to get it through your own means. One way to do so is by using the getID3 class. The link is just FYI, the class is built into WP. I’ve not used this class, so it’s all new to me as well. You could mimic what WP does to read audio ID3 data. Var_dump() the results of the analysis to see if album artist is even specified. The dump will tell you the correct key name to use if the data does exist.

    Thread Starter Epiphany

    (@epiphany1)

    @bcworkz
    Thank you very much for your support. After some days of research I finally solved the problem.
    Here what I did, wordpress picks up the Artist of the Audio, let’s say Luis Fonsi ft Daddy Yankee.
    So to get the album artist Luis Fonsi. I used str_replace to remove ft daddy Yankee. So that it will return only Luis Fonsi.

    But I have one last question, I want to use the audio featured image/ cover image as the featured image of any post it is attached to. Please help me out.

    Thank for your great support!

    Moderator bcworkz

    (@bcworkz)

    I don’t know how you would get the cover image. But if you can get the path to the cover image file, you then need a related attachment post in WP. Use wp_insert_attachemnt() to do so. With an attachment post that contains the image data, you make it the featured image of a specific post with set_post_thumbnail().

    FYI, featured images were initially called thumbnails when they were first introduced. This caused obvious confusion with thumbnail sized images, so the name was quickly changed to featured image. But all the related functions were already referencing thumbnails. It was decided to leave them be since those using PHP functions would be less likely to be confused between image size and a post’s primary image.

    Moderator bcworkz

    (@bcworkz)

    According to the answer in your other topic related to cover image, it sounds like the URL to the cover image is in the ID3 data. If so, you have the same problem where wp_read_audio_metadata() doesn’t even try to read that information. So the solution again is to use the getid3 class to get the needed URL.

    With the image URL, to get the image into WP, use media_handle_sideload(). Once in WP, you can set the post featured image as previously described.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Make wordpress read Album Artist id3 tag’ is closed to new replies.