0

I have a custom taxonomy named Country. The values include individual country names as well as an 'International' field that is supposed to represent all countries.

This is how it is supposed to work. If I lookup by the value 'International' it should find all posts that has only 'International' as the country value. However, if I lookup by the value 'USA', it should find all posts that has a country value of 'USA' plus all posts that has country value of 'International' filtering out any duplicate posts.

I could make international as a parent to all other country values, but it will actually have reverse impact as finding posts by International will also pull up posts that is exclusively meant for, say, USA. I suppose I can have something like the below,

query_posts( array(
  "tax_query" => array(
    array(
      "taxonomy" => "country",
      "field" => "slug",
      "terms" => array( "international", "usa" ),
      "operator" => 'AND'
    )
  )
) );

But do I have to do it for all country values? Or how to do it conditionally only when the field value is not 'International'?

redGREENblue
  • 3,076
  • 8
  • 39
  • 57

1 Answers1

0

Maybe do something that will loop all your filter and construct a different query_post filter array every time. I don't understand how you put country as "international", maybe there is a different approach to what you are trying to accomplish.

if ($filter)
        {
        $filterArray = array(
            'relation' => 'AND',
        );
        foreach($filter as $item)
            {
              //IF Statement here
            array_push($filterArray, array(
                'key' => 'country',
                'value' => $item,
                'compare' => '='
            ));
            }
        }
vico
  • 2,152
  • 2
  • 17
  • 38