Using Advanced Custom Fields\' Relationship Field to show attachments of a related post


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. foreach(get_field('relationship') as $related) :
  2. $args = array(
  3. 'post_type' => 'attachment',
  4. 'numberposts' => -1,
  5. 'post_status' => null,
  6. 'post_parent' => $related->ID,
  7. );
  8. $attachments = get_posts( $args );
  9. foreach ( $attachments as $attachment ) :
  10. $headshot = wp_get_attachment_image_src($attachment->ID, "medium");
  11. echo $headshot[0];echo "<br />";
  12. endforeach;
  13. endforeach;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.