Support

Account

Home Forums General Issues How to echo custom field from media attachment Reply To: How to echo custom field from media attachment

  • 
    <?php $block = 1;
    $content = apply_filters('the_content', get_the_content());
    $content = str_replace("/></a>", "/></a>
    
    <div class='under-image'>
    
    $attachments = get_attached_media('');
    if ($attachments) {
      foreach ($attachments as $attachment) {
        echo get_field('custom-field-name', $attachment->ID),'<br />';
      }
    }
    
    </div> <br>
    ", $content);
    $content = explode("</p>", $content);
    for($i = 0; $i < count($content); $i++ ) {if ($i == $block) { ?>
    
    <?php } echo $content[$i]. "";} ?>