0

I want to repeat this array:

array(
    'taxonomy' => $tax,
    'field'    => 'slug', 
    'terms'    => $cat,
)

because I am getting the value of taxonomy and categories from custom sub field

$args = array( 'post_type' => 'watches',  'tax_query' => array(
    array(
        'taxonomy' => $tax,
        'field'    => 'slug', 
        'terms'    => $cat,
        ),
    array(
        'taxonomy' =>  $taxonomy_2,
        'field'    => 'slug',
        'terms'    => $cat_2,
        ),
    array(
        'taxonomy' =>  $taxonomy_3,
        'field'    => 'slug',
        'terms'    => $cat_3,
        ),
    ),
);

1 Answer 1

0

Start by creating the arguments, but leaving tax_query empty:

$args = array(
    'post_type' => 'watches',
    'tax_query' => array(),
);

Then in your loop you can add to tax_querywith $args['tax_query'][] =:

$args = array(
    'post_type' => 'watches',
    'tax_query' => array(),
);

foreach ( $things as $thing ) {
    $args['tax_query'][] = array(
        'taxonomy' => $thing['taxonomy'],
        'field'    => 'slug', 
        'terms'    => $thing['term'],
    );
}

Exactly what you're looping over will likely affect what $things is and how you'd use it, but you didn't include that information in your question so I can't help beyond what I've already put.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.