Tag Info

Hot answers tagged


Because get_the_terms will not always return an array; it will be false if the post has no terms, or a WP_Error if the taxonomy does not exist - always sanity check the result before looping: $terms_slugs = array(); $terms = get_the_terms( $post->id, 'type', /* Note: get_the_terms does not take a 3rd argument ==> */ array( 'parent' => 0 ) ); if ( ...


You can use usort to sort the object $children. The function to sort after you got the $children object can be like this: usort( $children, function($a, $b) { $ai = filter_var($a->name, FILTER_SANITIZE_NUMBER_INT); $bi = filter_var($b->name, FILTER_SANITIZE_NUMBER_INT); if ($ai == $bi) { return 0; } return ($ai < $bi) ? ...

Only top voted, non community-wiki answers of a minimum length are eligible