admin管理员组

文章数量:1429450

I am trying to get the terms from all the taxonomies in an array. but this throws an error like this ..not sure why. Is it the wrong method?:

Fatal error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')'

public function pggggo_list_of_terms(){
    $terms = get_terms(
      'taxonomy' => array(
                     'vehicle_safely_features',
                     'vehicle_exterior_features',
                     'vehicle_interior_features',
                     'vehicle_extras')
    );  
    return $terms;
}

I am trying to get the terms from all the taxonomies in an array. but this throws an error like this ..not sure why. Is it the wrong method?:

Fatal error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')'

public function pggggo_list_of_terms(){
    $terms = get_terms(
      'taxonomy' => array(
                     'vehicle_safely_features',
                     'vehicle_exterior_features',
                     'vehicle_interior_features',
                     'vehicle_extras')
    );  
    return $terms;
}
Share Improve this question asked Apr 29, 2019 at 7:12 user145078user145078 1
  • You forgot about array( before 'taxonomy'. – nmr Commented Apr 29, 2019 at 7:15
Add a comment  | 

2 Answers 2

Reset to default 1

This is a PHP syntax error. You're attempting to pass an array to get_terms() but haven't used array() or [] to make it an array. This means that => is invalid here. The code should be:

public function pggggo_list_of_terms() {
    $terms = get_terms(
        [
            'taxonomy' => [
                'vehicle_safely_features',
                'vehicle_exterior_features',
                'vehicle_interior_features',
                'vehicle_extras',
            ],
        ]
    );

    return $terms;
}

or

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

    return $terms;
}

May be you are trying to do this. Passing arguments is wrong in your code.

public function pggggo_list_of_terms(){
    $terms = get_terms(
      'taxonomy', array(
                     'vehicle_safely_features',
                     'vehicle_exterior_features',
                     'vehicle_interior_features',
                     'vehicle_extras')
    );
    return $terms;
}

本文标签: custom taxonomygetterms()unexpected 39gt39 (TDOUBLEARROW) error