Delete the return links from the wp_list_categories() function;

Asked

Viewed 32 times

0

I’m trying to return only the list of taxomanias of a custom post type called "Portfolio". I only need the category names.

The code below is returning the categories with links, someone knows how to delete these links?

$taxonomy_names = get_object_taxonomies('portfolio');

if(count($taxonomy_names) > 0)
{
     foreach($taxonomy_names as $tax)
     {
         $args = array(
              'orderby' => 'name',
              'hide_empty' => 0,
              'show_count' => 0,
              'pad_counts' => 0,
              'hierarchical' => 1,
              'taxonomy' => $tax,
              'title_li' => ''
            );

        wp_list_categories($args);

     }
}

1 answer

0

According to the documentation of wp_list_categories in Wordpress Codex, there is an argument to omit the links in the list.

You can manually iterate using the function get_terms:

$taxonomy_names = get_object_taxonomies('portfolio');

if(count($taxonomy_names) > 0) {
    foreach($taxonomy_names as $tax) {
        $terms = get_terms($tax);

        foreach ( $terms as $term ){

            $output  = "";
            $output .= "<li>";
            $output .= $term->name;
            $output .= "</li>";

            echo $output;

        }
    }
}

This should return the result you want.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.