• Hey everyone;
    I’m working on a new site that I’m trying to achieve some very specific functionality for.

    Essentially, one of the columns in my footer shows the 5 most recent posts that are designated to the category ‘Bulletins’.
    Each bulletin will in turn have its own name (ex. Bulletin 1), and will have a short description as well. Each bulletin will also have a 1:1 relationship with a specific media file (ex. bulletin1.pdf).

    Since there is going to be 1 media file attached to 1 post, I would like to be able to devise some kind of method to determine (through PHP) the URL to the associated PDF file.
    Once I’ve achieved this, I will revise the loop displaying the 5 most recent posts so that the link goes directly to the PDF instead of to the post’s single page.

    Thanks for any help you can provide.

Viewing 1 replies (of 1 total)
  • Thread Starter corematt

    (@corematt)

    I received an answer offline that seems to be working for me.
    I’ll include it here in case it might be of help to anybody else

    <?php
    $images = get_children(
    array(
    'post_parent' => $post->ID,
    'post_type' => 'attachment',
    'order' => 'ASC',
    'orderby' => 'menu_order'
    )
    );
    $myAttachment = wp_get_attachment_url(current($images)->ID);
    ?>

    echoing $myAttachment gave me the URL that I needed.

Viewing 1 replies (of 1 total)
  • The topic ‘How To: Get Link to Post’s associated Media???’ is closed to new replies.