• Resolved madphill

    (@madphill)


    I’m attempting to pull media from posts by category and the media is showing up, it’s just not by category. It’s currently ALL media regardless of whether or not it’s attached to a post. I’m having trouble figuring out what to do.

    <div class="row-fluid">
    <?php
    global $post;
    $args = array(
    'post_category' => 'trees',
    'post_type' => 'attachment',
    'numberposts' => 8,
    'orderby' => 'random',
    'post_status' => null,
    'post_parent' => null, // any parent
    );
    $attachments = get_posts($args);
    foreach ($attachments as $post) : setup_postdata($post); ?>
    <div class="span3">
Viewing 5 replies - 16 through 20 (of 20 total)
  • Thread Starter madphill

    (@madphill)

    The lightbox is working, but the URL appears wrong. It’s nashvillebonsai.com/Array

    Hmm.. How about replace this line:

    $output .= wp_get_attachment_image_src( $attachment_id, "full" );

    with:

    $src = wp_get_attachment_image_src( $attachment_id, "full" );
    $output .= $src[0];

    That should get the first item in the array which is the URL.

    Thread Starter madphill

    (@madphill)

    I have no words to thank you. I’ve learned a lot (even though it may not seem that way). I’ll be breaking this down and studying it for a while I’m sure. You’ve done it!

    Thanks so much for all your help.

    Glad to hear it worked! Very nice looking website, by the way. I came across this thread by chance because of someone else who helped me with an issue, so I wanted to pass along the community goodness.

    Recently I’ve been working on a small plugin which (at least for me) simplifies the query and display of a variety of content, including attachments. It’s called Custom Content Shortcode in the WordPress repository, if you’re curious.

    Thread Starter madphill

    (@madphill)

    Very cool. I’ve favorited it and will check it out!

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Query posts with attachments by category’ is closed to new replies.