3

I have to get all the terms from four taxonomies:

  • vehicle_safely_features
  • vehicle_exterior_features
  • vehicle_interior_features
  • vehicle_extras

I tried this:

$terms = get_terms( array( 
    'taxonomy' => 'vehicle_safely_features',
    'vehicle_exterior_features',
    'vehicle_interior_features',
    'vehicle_extras'
) );

But, it only gets terms of vehicle_safely_features and not all of the taxonomies.

3 Answers 3

6

If you want to retrieve multiple taxonomies you need to put the four taxonomies in an array, you are doing this, but you have put taxonomy=> in the array.

$terms = get_terms(
          'taxonomy' => array(
                         'vehicle_safely_features',
                         'vehicle_exterior_features',
                         'vehicle_interior_features',
                         'vehicle_extras')
);

Hope it helps

1
  • Thanks Benoti that did the trick I knew I was missing something.
    – apoorv
    Nov 15, 2016 at 8:03
3

Incase someone get an error due to the => use below

$termsArray = get_the_terms(
    $post->ID,
    array(
        'tax1',
        'tax2',
        'tax3'
    )
)
1
0

wp_get_post_terms accepts multiple taxonomies as opposed to get_the_terms suggested by another answer.

$terms = wp_get_post_terms(
    $post->ID,
    array(
        'tax1',
        'tax2',
        'tax3'
    )
)

Resource

https://developer.wordpress.org/reference/functions/wp_get_post_terms/

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.