Your problem is $tax_country
, more actually the value. get_the_term_list()
does not return what you think
Returns an HTML string of taxonomy terms associated with a post and given taxonomy. Terms are linked to their respective term listing pages.
Even if you strip away the tags, you will just be left with a string of term names. WP_Query
(which is used in get_posts
) do at times for some reason fails this way (returns all posts and ignores the posts_per_page
value) if invalid values are passed to it.
To sort your issue, make use of wp_get_post_terms()
. You can try something like the following
$tax_country = wp_get_post_terms( $post->ID, 'country', array( 'fields' => 'ids' ) );
This will return an array of term ids, so you will need to adjust your tax_query
to something like this
'tax_query' => array(
array(
'taxonomy' => 'country',
'terms' => $tax_country,
'include_children' => false
)
),