[resolved] Attachment URL (2 posts)

  1. joshrodgers
    Posted 4 years ago #

    I think this is a simple fix, but I'm not sure what I'm doing wrong. If someone could point me in the right direction, I'd appreciate it ;)

    Ok, so, what I have is a custom meta box using the following code: http://pastebin.com/aVt5FxNk

    Basically a user chooses one of the audio files that they've uploaded to the media library on the back-end. I have that code working without an issue. What I'd like to do is get the full url of the audio file so I can use it in my theme on the front-end.

    What I was able to do is: http://pastebin.com/414Hj6Af

    This code outputs: http://joshtx.com/bandits/wp-content/uploads/One-eyed Maestro.mp3

    This is close, but it's not the full url that I wanted.

    The full url is actually: http://joshtx.com/bandits/wp-content/uploads/2011/10/One-eyed-Maestro.mp3

    Anyone know how I can get the full path to the audio file?


  2. joshrodgers
    Posted 4 years ago #

    I solved the problem :)

    Ok, my custom meta box code didn't change, it still looks like: http://pastebin.com/aVt5FxNk

    My original template code looked like this: http://pastebin.com/414Hj6Af

    I did a few things to make this work:

    First...I defined my upload directory: http://pastebin.com/jpTLCTfs

    Then...I defined my filename: http://pastebin.com/ss0kTkbH

    After that...I changed line 3 of my original template code. Instead of: http://pastebin.com/gGuU0hKA my code looks like: http://pastebin.com/K0gE8CNA.

    The line adds the upload directory, a slash, the filename and then a replace to remove the spaces and replace them with hyphens in the filename (because WordPress automatically removes the spaces and adds hyphens to the actual filename).

    All together, the final code looks like: http://pastebin.com/n8272A44

    Once you have the link, then you can use it as a background sound or in a music player. Just make sure you use line 7 of http://pastebin.com/n8272A44 as your embed source.

    That's it! Not too bad :)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.