0

I am trying to use the isotope plugin for sorting on my taxonomy page and even though I don't know much about how to set it up, I tried using some advice found on here.

Wordpress and isotope filtering

I did so by taking this code

function isotope_categories() {

        $categories = get_categories();

        $html = '<ul class="filters option-set" data-option-key="filter">';
        $html .= '<li><a href="#filter" data-option-value="*" class="selected">All items</a></li>';

        foreach ($categories as $category) {

            $html .= "<li><a href='#filter' data-option-value='.category-{$category->category_nicename}'>{$category->cat_name}</a></li>";   
        }

        $html .= '</ul>';

        echo $html;
    }

and tried altering it so that it would work with get_terms (custom taxonomy). The code I ended up with is -

function isotope_categories() {

        $categories = get_terms();

        $html = '<ul class="filters option-set" data-option-key="filter">';
        $html .= '<li><a href="#filter" data-option-value="*" class="selected">All items</a></li>';

        foreach ($terms as $term) {

            $html .= "<li><a href='#filter' data-option-value='.category-{$term->name}'>{$term->name}</a></li>";   
        }

        $html .= '</ul>';

        echo $html;
    }

However when I use <?php isotope_categories() ?> in my taxonomy page I receive the following errors -

Warning: Missing argument 1 for get_terms(), called in html/wp-content/themes/lawcademy_theme/functions.php on line 1667 and defined in html/wp-includes/taxonomy.php on line 1165

Warning: Invalid argument supplied for foreach() in html/wp-content/themes/lawcademy_theme/functions.php on line 1672

How can I fix the code so that I don't get these errors?? Any help is appreciated. Thanks.

0

get_categories() does not require parameters, by default it will query the post type post and the taxonomy category. However, get_terms() require a taxonomy parameter.

Also, in the second function, you wrote:

 $categories = get_terms();

It should have been

$terms = get_terms('your_taxonomy');
  • Thanks!! That fixed the problem. Now I just need to figure out how to get isotopes to work properly so that I can sort posts. TWO MORE QUESTIONS - Is there a way to modify the above code so that only the sub categories of the current page show? And how can I modify it to be a drop down instead of a list? – Rich Dec 19 '12 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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