I have some code that returns the latest 5 images from the WordPress Media Library:
<?php
$excluded = array(1,35,37);
$args = array(
'post_type' => 'attachment',
'numberposts' => '5',
'category__not_in' => $excluded
);
$images = get_posts($args);
if (!empty($images)) {
?>
<div class="wrap">
<h5><span>Recently</span> Added</h5>
<ul>
<?php
foreach ($images as $image) {
$attachment_link = get_attachment_link( $image->ID );
echo "<li><a href='".$attachment_link."'>".wp_get_attachment_image($image->ID)."</a></li>";
}
?>
</ul>
</div>
<?php } ?>
I'm excluding some categories that I do not want to display (1,35,37). This works, but sometimes I have multiple categories assigned in addition to the excluded categories...if category 1 is selected and category 15 is selected the image will not show because category 1 is selected.
What I am trying to do is exclude the categories only if those categories are selected by themselves. If they are selected with another category that isn't excluded they should show. So, an image that has category 1 and category 12 selected should still show because category 12 is not part of my excluded list.
Can anyone point me in the right direction?
Thanks,
Josh