Exclude a meta key value from second loop
-
I have two loops. One loop pulls posts for the meta_value $artist_name. The second loop pulls posts from a search of $artist_name but I need to exclude the meta_value $artist_name. I tried using ‘meta_compare’ => ‘!=’ but it’s still showing the posts with the meta_value. Here’s the two loops. What am I missing?
<?php global $artist_name; $args = array( 'showposts' => 8, 'order' => 'DESC', 'cat' => '3', 'meta_key' => 'artist_name', 'meta_value' => $artist_name, ); query_posts($args); if (have_posts()) : ?> <?php while (have_posts()) : the_post(); if($current_post_id==get_the_ID()) continue; ?> <?php global $artist_name; $search_term = get_post_meta($post->ID,'artist_name',true); $args = array('cat' => '3', 'posts_per_page' => 4, 's' => $search_term, 'meta_key' => 'artist_name', 'meta_value' => $artist_name, 'meta_compare' => '!='); $my_search = new WP_Query($args); if ($my_search->have_posts()) : while ($my_search->have_posts()) : $my_search->the_post(); ?>
- The topic ‘Exclude a meta key value from second loop’ is closed to new replies.