I have a Custom Post Type for "Products" with a Custom Taxonomy of "Product Line." I've set up a page to list out the Products by their Product Line. However, we're also using a Product Line of "Featured Products" to use on the Homepage only. We do not want "Featured Products" to display within the "All Products" page. I have the following loop.
<?php
$post_type = 'products';
$taxonomies = get_object_taxonomies( $post_type );
foreach ($taxonomies as $taxonomy){
$terms = get_terms($taxonomy, array('orderby' => 'date', 'order' => 'ASC'));
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
$args = array(
'post_type' => $post_type,
'orderby' => 'date',
'order' => 'ASC',
'ignore_sticky_posts' => 1,
'post_status' => 'publish',
'posts_per_page' => - 1,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term->slug,
'operator' => 'IN'
),
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => 'featured-products',
'operator' => 'NOT IN'
)
)
);
$my_query = null;
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
echo '<div class="resource"><h2>' . $term->name . '</h2>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<ul>
<li>
<div class="resource_image_helper">
<a href="<?php the_permalink(); ?>"><img src="<?php the_field('mobile_image'); ?>"></a>
</div>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<ul>
<?php
// Grab the title and change for slug
$title = get_the_title();
$stripped = sanitize_title_with_dashes($title);
$literature = do_shortcode('[downloads category='.$stripped.']');
$photos = get_field('tab_photos');
?>
<?php if(!empty($photos)): ?>
<li>
<a href="<?php the_permalink(); ?>">Photos</a>
</li>
<?php endif; ?>
<li>
<a href="<?php the_permalink(); ?>">Videos</a>
</li>
<?php if(!empty($literature)): ?>
<li>
<a href="<?php the_permalink(); ?>">Literature</a>
</li>
<?php endif; ?>
</ul>
</li>
</ul>
<?php
endwhile;
echo '</div>';
} // END if have_posts loop
wp_reset_query();
} // END foreach $terms
}
}
?>
The problem I'm having is with the tax_query
portion. I do not want to show the "Featured Products" term, which I've done. But with this code, it doesn't show any products that are withing "Featured Products." I still need the Products to show under other Product Line terms, I just need the Featured Products term to not be displayed. Any ideas?