Support » Developing with WordPress » Saving and Retrieving The Number of Plays of a Playlist File

  • Resolved starapple

    (@starapple)


    I’ve found some code on Stack Exchange to save and print for the admin the number of times a song is played from a playlist. However, I’m having difficulty retrieving the saved data for public display in a list of top songs similar to top posts.

    I’ve taken a visual peek at _wp_attachment_metadata in the postmeta table and I see info for photos but not a single audio file although there are 72 that all show in the post table.

    A search of the database using phpMyAdmin doesn’t find the plays_ips and plays fields listed in the code linked above so I’m very much at sea trying to use get_post_meta( $post_id, '_wp_attachment_metadata', true ) ); with those filters.

    I’m ending up with a list of post titles rather than song titles.

    Thanks for any help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    That SE code is a bit old, we should expect to need to make adjustments. If you cannot find a play count for a particular audio file that you know has been played, the jQuery is most likely failing. Be sure the jQuery selector is still correct for your page’s audio tags. The tags should have the class “wp-audio-shortcode” or its container should have class “wp-audio-playlist”.

    Check you browser console for script errors. An unrelated error can prevent the play count script from running.

    I’m not sure where you are trying to get song titles. The SE code only logs plays and IPs, for files with a specific GUID, no titles (though it could be part of the GUID, but would not be formatted correctly for display. Can you see song titles when you view meta data through phpMyAdmin? If so, there will be a way to get at them.

    I don’t know if the hidden characteristics of _wp_attachment_metadata is the problem for me. It shouldn’t since the count shows in the meta box at the top right of the audio editing screen.

    I got the attachment meta for the post (page), which contains ID, guid, title and all that. My intention was to fetch the IDs and titles then use the IDs ($post_id) to loop through get_post_meta. But no result shows for _wp_attachment_metadata.

    • This reply was modified 1 year, 1 month ago by  starapple.
    Moderator bcworkz

    (@bcworkz)

    Well, if the count is displayed, it’s saved somewhere 🙂 But finding it can be difficult. Best thing would be to examine the source code for the edit meta box and learn how it is getting the value. Unless you’ve clearly seen it in _wp_attachment_metadata, it must be saved elsewhere.

    Are you saying you get nothing with
    get_post_meta( $post_id, '_wp_attachment_metadata', true ) )?
    If so, I’d suspect the ID source is in error.

    starapple

    (@starapple)

    I’ll have to get back to it later @bcworkz. I’m sure there’s something wrong with what I’m doing through lack of full knowledge because even when I use get_the_ID() for $post_id the result is the same; yet I know for sure that three audio files attached to the post have saved play data.

    I was planning DIY using the [playlist] tag rather than go for plugin overkill but now find myself with a plugin and an add-on that counts, only again, with nothing on the front end. I’ll have to see whether I can make a shortcode to print what’s in the back-end on the front in a widget.

    So many already built in features hidden in obscurity with plugins duplicating and triplicating… Not resolved but I’ll close this. Thanks for spending your time helping.

    • This reply was modified 1 year ago by  starapple.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Saving and Retrieving The Number of Plays of a Playlist File’ is closed to new replies.