Can anyone tree_sort() my term->children() ?

20 views
Skip to first unread message

David Golding

unread,
May 31, 2012, 5:59:11 AM5/31/12
to habar...@googlegroups.com
I'm getting the results of term->children() not sorted. I can't seem to get my children nicely ordered the same as get_tree($orderby= 'mptt_left ASC') 
Am I missing something obvious?

$html = '';

// don't want entire tree
// $rt = $this->vocabulary->get_tree();
// Instead would like to work on root terms rt

$rt = $this->vocabulary->get_root_terms(); 

foreach ( $rt as $term_ob )
{
    $children = $term_ob->children();
    // $children->tree_sort(); fails here as non-object
    $html .= Format::term_tree($children, 'test_tree_name', array());
}

echo $html;




Owen Winkler

unread,
May 31, 2012, 8:04:32 AM5/31/12
to habar...@googlegroups.com
On 5/31/2012 5:59 AM, David Golding wrote:
> I'm getting the results of term->children() not sorted. I can't seem to
> get my children nicely ordered the same as get_tree($orderby= 'mptt_left
> ASC')
> Am I missing something obvious?

In your example, $term_ob->children() returns an array. If you want to
call ->tree_sort() on the result, then it needs to be an instance of
Terms. You can do that like this:

$children = new Terms($term_ob->children());

I'm not sure why it doesn't already return Terms, so I'll likely make
that change today. Besides that, I can't think of a reason why it
should return the terms out of order to begin with - at any level - so
I'll see if I can have both get_root_terms() and children() return their
results in tree order.

Owen

David Golding

unread,
Jun 1, 2012, 6:09:01 AM6/1/12
to habar...@googlegroups.com

Thank you :-)  
Reply all
Reply to author
Forward
0 new messages