• OK what I’m trying to do is basically show all the image attachments of posts from a certain catagory. I used wp_query to do a loop of the correct posts and now I want to get all the images using get_posts.

    Here is my code:
    https://pastebin.com/Qst46Fu1

    For debugging I put echo "get posts didn't work for ". $post->ID . "<br/>"; if $attachments is undefined. So far this is all that is returned. I.e. I get:

    get posts didn’t work for 1954
    get posts didn’t work for 1806
    get posts didn’t work for 1625
    get posts didn’t work for 1293
    get posts didn’t work for 1150
    get posts didn’t work for 1129 etc

    Any ideas on how to get it working? Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try using a post_status of ‘inherit’.

    Thread Starter miocene22

    (@miocene22)

    Thanks for the reply – unfortunately that didn’t work.

    Been away for a couple of weeks – now going to try and resurrect this thread…

    Really odd, it worked for me and I have used it before. You did try it like this:

    //Call a post image attachment
    $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => 'inherit', 'post_parent' => $post->ID );
    $attachments = get_posts($args);

    with quotes around inherit?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Getting the post attachments’ is closed to new replies.