• Resolved David Ruszkowski

    (@dmrgraphics)


    I added a upload custom field to a post that returns a list of PDF files related the the post.

    The code I am using, which is working fine, is like this:

    <!-- Custom Links for Events Page -->
    <div class="event-file-downloads">
    <?php
    $pdfdownloadlink = get_post_meta($post->ID, 'pdfdownloadlink', true);
    foreach($pdfdownloadlink as $pdfdownloadlink) {
    $file_attributes = wp_get_attachment_url( $pdfdownloadlink['file-upload'] );
    echo '<strong>File Downloads: </strong>';
    echo '<a href="' . $file_attributes . '" >';
    echo '[ ';
    echo $pdfdownloadlink['file-link-name'];
    echo ' ] ';
    echo '</a>';
    }
    ?>
    </div>
    <!-- End Custom Links for Events Page -->

    What I need to do is call this outside the loop. Most of what I have seen uses something like this to call custom fields outside the loop:

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'customField', true);
    ?>

    I tried adding global $wp_query; to the original code, that didn’t work. I am just not sure how to modify it to get it to work. Any help anyone could offer would be appreciated.

    Thanks.

    http://wordpress.org/extend/plugins/custom-fields-creator/

Viewing 1 replies (of 1 total)
  • Thread Starter David Ruszkowski

    (@dmrgraphics)

    I guess when I can’t get something to work I should post it here, because usually a couple minutes after that I figure it out…

    I added the global query stuff, but had to change $post->ID in my original code to $postid. The one that worked looks like this.

    <!-- Custom Links for Events Page -->
    <div class="event-file-downloads">
    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $pdfdownloadlink = get_post_meta($postid, 'pdfdownloadlink', true);
    foreach($pdfdownloadlink as $pdfdownloadlink) {
    $file_attributes = wp_get_attachment_url( $pdfdownloadlink['file-upload'] );
    echo '<strong>File Downloads: </strong>';
    echo '<a href="' . $file_attributes . '" >';
    echo '[ ';
    echo $pdfdownloadlink['file-link-name'];
    echo ' ] ';
    echo '</a>';
    }
    ?>
    </div>
    <!-- End Custom Links for Events Page -->
Viewing 1 replies (of 1 total)
  • The topic ‘Get Attachment URL – Using it outside the loop?’ is closed to new replies.