0

Using Wordpress, i have a plugin that inserts a playable MP3 on the page.

To call that, along with the track details, this code is inserted;

            <?php if (function_exists("insert_audio_player")) {  
              insert_audio_player("[audio:http://thewebsite.com/thetrack.mp3|artists=Artist|titles=Titles]");  
            } ?>

I would like to make this editable from the backend easily, by entering some meta-data. So this;

<?php meta('track-url'); ?>

Along with other various details would replace those that are above.

Unfortunately for me, this;

                <?php if (function_exists("insert_audio_player")) {  
              insert_audio_player("[audio:<?php meta('track-url'); ?>|artists=Jack Presto|titles=Track 1]");  
            } ?>

obviously does not work! This is down to my lack of understanding if PHP - can anyone help?

Cheers!

1
  • 1
    See PHP: String operators - you need to glue the parts together using ., e.g. "[audio:".meta("track-url")."|artists...." Commented Oct 3, 2011 at 15:04

2 Answers 2

3

Simple! Do this:

<?php if (function_exists("insert_audio_player")) {
   $trackUrl = meta('track-url');
   insert_audio_player("[audio:$trackUrl|artists=Jack Presto|titles=Track 1]");  
} ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, so i went ahead and read the linked part and remembered seeing something similar and kind of combined them all and came out with this; <?php $trackartist=get_post_meta($post->ID, 'track-artist', true); ?> <?php $trackname=get_post_meta($post->ID, 'track-name', true); ?> <?php $trackurl=get_post_meta($post->ID, 'track-url', true); ?> <?php if (function_exists("insert_audio_player")) { insert_audio_player("[audio:$trackurl|artists=$trackartist|titles=$trackname]"); } ?> It works, but probably not as clean as it should be? Cheers!
0

I can't tell if the meta() function prints to the screen or returns a string. If it returns a string, do:

<?php
if (function_exists("insert_audio_player")) {  
     insert_audio_player('[audio:' . meta('track-url') . '|artists=Jack Presto|titles=Track 1]');  
}
?>

If it prints to the screen, it's a bit more complicated. Ideally, you would have a function that DOES return a string, but as a quick hack (if you're only getting paid for a quick fix) you could do something like

<?php
if (function_exists("insert_audio_player")) {  
     ob_start();
     meta('track-url');
     $meta = ob_get_contents();
     ob_end_clean();
     insert_audio_player("[audio:$meta|artists=Jack Presto|titles=Track 1]");  
}
?>

1 Comment

It's wordpress, so any function which produces output generally has a get_whatever() version to RETURN the output instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.