wordpress grab the meta_key value url

Asked

Viewed 531 times

0

I would like to get the separate value url placed on meta_key , I have a custom field "Custom file" called mp3 then put the mp3 multiple fields would like to pick url of each value

this code below shows the url only of the last mp3 added:

<?php $minha_variavel = get_post_meta($post->ID, 'mp3', true); ?>

<?php if ($minha_variavel): ?>
<?php echo wp_get_attachment_url($minha_variavel); ?>
<?php endif; ?>
  • get_post_meta() receives a boolean parameter called single, that determines whether the function return is a single value or an array of values. In your case, you are calling the function with that value as true. Try to leave it as false.

  • Good morning ! set to false now displayed nothing in case I have to put the code inside a loop or not in case it is a field with multiple volumes

  • if $minha_variavel for an array, you will have to traverse it in a loop

1 answer

0

Adding what colleagues commented on your question the code would look like this:

$minha_variavel = get_post_meta($post->ID, 'mp3'); // O terceiro parâmetro é FALSE por padrão

foreach ($minha_variavel as $arquivo) { // Segundo a documentação o retorno é sempre um array
    echo wp_get_attachment_url($arquivo);
}
  • It is printed the URL of the files but I would like to pick separate example: url of value 2 only of the second file placed in meta_key ha since thank you very much for the force of vcs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.