WordPress wp_get_category sort order workaround

While working on a WordPress website I stumbled on a strange issue with the wp_get_category function.

For some reason on my category archive page, the first item from the array returned by the wp_get_category function contained the first parent item … but from within an other category, the first parent item was the last item of the returned array.

This little code snippet resolved my issues, giving an categories array where the first item is always the first parent.

1
2
$cats = get_the_category();
if ($cats[0]->parent != 0) $cats = array_reverse($cats);

Tags: ,

Reacties

1 reactie op "WordPress wp_get_category sort order workaround"

  • VitaliiZvyagintsev | 7 November 2013 - 06:56

    Regular Bundle, for sites of all kindsAll-in-one bundle to cover all types of websites, ranging from magazines, business websites, portfolios, for photo and video sharing sites. Topics include: Arthemia, Allegro, Adam & more http://lc-s.co/LsmHeosV

Laat een reactie achter