0

I am trying to show all the terms from these taxonomies. However, I can't get them working. Please help, thanks

<?php 
$terms = get_terms(
    'taxonomy' => array(
        'category',
        'profile_status',
        'profile_skill')
);

if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    echo '<ul>';
    foreach ( $terms as $term ) {
        echo '<li>' . $term->name . '</li>';
    }
    echo '</ul>';
}

?>

1 Answer 1

1

Your get_terms is causing a parse error, you are missing the array part.

Also when using get_terms take into account that by default it will not return taxonomies that don't have posts attached to them.

The proper code would be like this

$terms = get_terms([
    'taxonomy' => [
        'category',
        'profile_status',
        'profile_skill'
    ]
]);

If you want to include empty taxonomies (taxonomies without posts attached to them), do this

$terms = get_terms([
    'taxonomy' => [
        'category',
        'profile_status',
        'profile_skill'
    ],
    'hide_empty' => false
]);

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.