I’m moving edit post dashboard to front end.
So here is a case, I have to queries, one for product attachments and other for ALL.
Now, I want to exclude product attachments from ALL attachments query
here is an example how to exclude post thumbnail from WordPress Codex:
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id()
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo apply_filters( 'the_title', $attachment->post_title );
the_attachment_link( $attachment->ID, false );
}
}
?>
before that, I have a query of all products, so can exclude
take array argument? For example with my code
$mediaArgs = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $current_post,
);
$MediaAttachments = get_posts($mediaArgs);
Can I then foreach this and save MediaAttachment->ID inside some array and exclude put it next tu exclude
? In my theory it should work as usual, but no matter how I tried, it does not work.
Strange but it works with same principle I was trying to. Maybe I had some grammer error. Here is a code if somebody will need it in future as there was nothing in search result:
Where
$parentMediaArray
is the array which I exclude