0

I am trying to add an audio file to my custom post type using a custom term meta field as a link, but I can't get it right.

Here is how I would normally display a custom term meta field:

<?php $terms = get_the_terms($post->ID, 'taxonomy-name');
foreach ($terms as $term) {
$term_id = $term->term_id;
echo get_term_meta( $term_id, 'term-meta-field-name', true );
}?>

I'm assuming I have to turn it into a variable, but I'm not sure how. Any ideas?

<?php echo do_shortcode([audio src="link"]); ?>

Thanks!

closed as unclear what you're asking by Jacob Peattie, mmm, bosco, TheDeadMedic, Jack Johansson Aug 8 '18 at 23:43

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

0

I figured it out!

Using this code I was able to use my custom meta field as the link in the audio shortcode.

First I created a function in functions.php:

function audio_link() {
    $terms = get_the_terms($post->ID, 'taxonomy-name');
    $result = "";
    if (is_array($terms) || is_object($terms)){
    foreach ($terms as $term) {
    $term_id = $term->term_id;
    $result .= get_term_meta( $term_id, 
    'term-meta-field-name', true );
        }
    }
        return $result;
    }

Then I inserted the function into the shortcode like this:

<?php echo do_shortcode('[audio src="'. audio_link() .'"]');?>

Hope this helps anyone else with this problem!

Not the answer you're looking for? Browse other questions tagged or ask your own question.