0

I have this code :

if($pf_categorynotin){
    $args['tax_query'] = array(
        array(
            'taxonomy' => 'portfolio_category',
            'field' => 'slug',
            'terms' => $pf_categorynotin,
            'operator' => 'NOT IN'
        )
    ); //category__in
}

It has one taxonomy defined which is portfolio_tag. What I want to do is to add another taxonomy like portfolio_tag

I'm not sure if will work like this: 'taxonomy' => 'portfolio_category', 'portfolio_tags',

Basically what I want to do is add also another taxonomy in that array.

agis
  • 1,831
  • 10
  • 33
  • 68
  • 1
    You should edit your question to explain that this array will be use as param for WP_Query – soju Sep 19 '12 at 14:53

5 Answers5

1

Take a look at "Multiple Taxonomy Handling" example here : http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

$args['tax_query'] => array(
    'relation' => 'AND',
    array(
        'taxonomy' => 'portfolio_category',
        'field' => 'slug',
        'terms' => $pf_categorynotin,
        'operator' => 'NOT IN'
    ),
    array(
        'taxonomy' => 'portfolio_tags',
        'field' => 'slug',
        'terms' => $pf_categorynotin,
        'operator' => 'NOT IN'
    )
);

You should adapt relation and operator to fit your needs.

soju
  • 25,111
  • 3
  • 68
  • 70
0

If you want more than one value you have to use an array, so replace your following line:

'taxonomy' => 'portfolio_category',

for this one:

'taxonomy' => array('portfolio_category','portfolio_tags'),

but remember that the code that reads $args['tax_query'] will have to be adapted to take into account that $args['tax_query'][0]['taxonomy'] could now be an array or a string.

Nelson
  • 49,283
  • 8
  • 68
  • 81
0

You could make an array out of taxonomy so your code would look like:

if($pf_categorynotin){
    $args['tax_query'] = array(
        array(
            'taxonomy' => array('portfolio_category', 'portfolio_tags'),
            'field' => 'slug',
            'terms' => $pf_categorynotin,
            'operator' => 'NOT IN'
        )
    ); //category__in
}

and than $args['tax_query'][0]['taxonomy'][0] will be 'portfolio_category' and $args['tax_query'][0]['taxonomy'][1] will be 'portfolio_tags'

19greg96
  • 2,592
  • 5
  • 41
  • 55
0
if($pf_categorynotin){
    $args['tax_query'] = array(
        array(
            'taxonomy' => array('portfolio_category','portfolio_tags'),
            'field' => 'slug',
            'terms' => $pf_categorynotin,
            'operator' => 'NOT IN'
        )
    ); //category__in
}

could do the trick

Sonaryr
  • 1,092
  • 1
  • 10
  • 24
0

taxonomy needs to be another array for example:

$taxonomy = array(tax1, tax2, tax3);

then you add

array(
            'taxonomy' => $taxonomy,
            'field' => 'slug',
            'terms' => $pf_categorynotin,
            'operator' => 'NOT IN'
        )
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
pl4g4
  • 101
  • 4