I’m weak on query arguments myself, but I would try
'post_parent' => array( 1, 2, 3, 4 ),
to get attachments that are children of any of the listed post IDs. If I correctly understand what you are asking.
🙁 not working.
example:
Post A – 2 attachments
Post B – 1 attachments
Post C – 3 attachments
$args = array(
'post_type' => 'attachment',
'meta_key' => 'gosterilecek_tab',
'meta_value' => 'tab-2',
'numberposts' => -1,
'post_status' => 'inherit',
??'post_parent' => A,B,C,
'exclude' => get_post_thumbnail_id()
);
result of listing :
total listing item: 6
I do not know english. I’m sorry
Please explain what output you are expecting. More code showing how $args is used may also help.
ok, bcworkz
$html_tab_images_3 = '';
$args = array(
'post_type' => 'attachment',
'meta_key' => 'gosterilecek_tab',
'meta_value' => 'tab-2',
'numberposts' => -1,
'post_status' => 'inherit',
//'post_parent' => get_field('tab-2-icerik-id'),
//'post__in' => array(2744,2748),
'exclude' => get_post_thumbnail_id()
);
$attachments_3 = get_posts( $args );
if( $attachments_3 ) {
$i = 1;
$html_tab_images_3 .= '<div id="pimages-2" class="tab-content" style="margin-left:15px;">';
foreach( $attachments_3 as $attachment ) {
if( $i % 4 == 0 ) $switch_class = ' alpha omega';
elseif( ( $i - 4 ) % 2 == 0 ) $switch_class = '';
else $switch_class = '';
$large_image_url = wp_get_attachment_image_src( $attachment->ID, 'large' );
$html_tab_images_3 .= '<span style="width: 130px;" class="prodimgwrap alignleft' . $switch_class . '"><a href="' . $large_image_url[ 0 ] . '" title="' . the_title_attribute( 'echo=0' ) . '">';
$html_tab_images_3 .= wp_get_attachment_image( $attachment->ID, 'thumbnail' );
$html_tab_images_3 .= '</a><span class="imgshadow"><span class="shadowleft"> </span><span class="shadowright"> </span></span></span>';
$i ++;
}
echo '</div>';
}
example:
Post A – 2 attachments
Post B – 1 attachments
Post C – 3 attachments
I think I understand now, the above is the output you want, but you are getting the 6 attachments run together and not associated with any posts. Correct?
If correct, you need to wrap your code in another foreach loop that steps through each post and retrieves the attachments for each post in turn. Note in this example, I am using pre defined post ID numbers. If you need to use some other method to identify the posts, more coding will be required.
$parents = array(1,2,3); //use the actual post ID numbers here
foreach($parents as $parent) {
$args = array(
//insert any other needed args here
'post_parent' => $parent
);
$title = get_the_title($parent);
$html_tab_images_3 .= "<h2>$title</h2>";
//insert get and print attachments code here
}
Not tested, some corrections may be required. Note your code is echoing a single </div> before $html_tab_images_3 is output. The </div> should be concatenated to $html_tab_images_3 so the tags balance.
I will be AFK for some time, so someone else will need to answer any further questions. I hope you can understand my native English:) Good luck.