There is a descriptively named argument to WP_Query
, which is what you should be using, called post__not_in
which excludes any post ID
s passed into it.
Also, the {tax} => {term_name}
pattern that you have used twice is deprecated. You should be using a tax_query
argument instead.
Lines like this one, strip_tags( get_the_term_list( $wp_query->post->ID, 'buyers-club' ) );
, will fail if more than one term is returned. That is not the way you should be doing this. That function isn’t meant for returning a list of slugs.
It should look something more like this:
$country_name = wp_list_pluck(get_the_terms( 1, 'country' ), 'term_id')
$category_name = wp_list_pluck(get_the_terms( 1, 'buyers-club' ), 'term_id')
$args = array(
'post_type'=> 'buyers_club',
'tax_query' => array(
array(
'taxonomy' => 'buyers-club',
'field' => 'id',
'terms' => $category_name
),
array(
'taxonomy' => 'country',
'field' => 'id',
'terms' => $country_name
)
),
'order' => 'rand',
'post__not_in' => array($post->ID),
'posts_per_page' => 5
);
$buyer_club = new WP_Query( $args );
if ($buyer_club->have_posts()) {
while ( $buyer_club->have_posts() ) {
$buyer_club->the_post();
echo '<li>';
the_title();
echo '</li>';
}
}