public static function getWhere($args = array())
    {
        $instance = Term\Factory::create(get_called_class());

        // Allow sorting both by core fields and custom fields
        // See: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
        $default_args = array(
            'orderby' => $instance->getDefaultOrderBy(),
            'order' => $instance->getDefaultOrder(),
            'hide_empty' => false, // Note: This goes against a WordPress get_terms default. But this seems more practical.
        );

        $criteria = array_merge($default_args, $args);

        // Custom ordering
        $orderby = null;
        $order = null;
        $wordpress_sortable_fields = array('id', 'name', 'count', 'slug', 'term_group', 'none');
        if (array_key_exists('orderby', $criteria) && !in_array($criteria['orderby'], $wordpress_sortable_fields)) {
            $orderby = $criteria['orderby'];
            $order = (array_key_exists('order', $criteria))
                ? strtoupper($criteria['order'])
                : 'ASC';
            unset($criteria['orderby']);
            unset($criteria['order']);
        }

        $criteria['taxonomy'] = $instance->getTaxonomyKey();
        $terms = Term\Factory::createMultiple(get_terms($criteria));

        // We might be done
        if (!Arr::iterable($terms)) {
            return $terms;
        }
        if (!$orderby) {
            return $terms;
        }

        // Custom sorting that WordPress can't do
        $field = $instance->getField($orderby);

        // Make sure we're sorting numerically if appropriate
        // because WordPress is storing strings for all vals
        if ($field['type'] === 'number') {
            foreach ($terms as &$term) {
                if (!isset($term->$orderby)) {
                    continue;
                }
                if ($term->$orderby === '') {
                    continue;
                }

                $term->$orderby = (float) $term->$orderby;
            }
        }

        // Sorting
        $sort_flag = ($field['type'] === 'number') ? SORT_NUMERIC : SORT_STRING;
        $terms = Collection::sortBy($terms, $orderby, $sort_flag);
        if (strtoupper($order) === 'DESC') {
            $terms = array_reverse($terms, true);
        }

        // Convert back to string as WordPress stores it
        if ($field['type'] === 'number') {
            foreach ($terms as &$term) {
                if (!isset($term->$orderby)) {
                    continue;
                }
                if ($term->$orderby === '') {
                    continue;
                }

                $term->$orderby = (string) $term->$orderby;
            }
        }

        return $terms;
    }
public static function getWhere($args = array())
    {
        $instance = Term\Factory::create(get_called_class());

        // Allow sorting both by core fields and custom fields
        // See: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
        $default_args = array(
            'orderby' => $instance->getDefaultOrderBy(),
            'order' => $instance->getDefaultOrder(),
            'hide_empty' => false, // Note: This goes against a WordPress get_terms default. But this seems more practical.
        );

        $criteria = array_merge($default_args, $args);

        // Custom ordering
        $orderby = null;
        $order = null;
        $wordpress_sortable_fields = array('id', 'name', 'count', 'slug', 'term_group', 'none');
        if (array_key_exists('orderby', $criteria) && !in_array($criteria['orderby'], $wordpress_sortable_fields)) {
            $orderby = $criteria['orderby'];
            $order = (array_key_exists('order', $criteria))
                ? strtoupper($criteria['order'])
                : 'ASC';
            unset($criteria['orderby']);
            unset($criteria['order']);
        }

        $criteria['taxonomy'] = $instance->getTaxonomyKey();
        $terms = Term\Factory::createMultiple(get_terms($criteria));

        // We might be done
        if (!Arr::iterable($terms)) {
            return $terms;
        }
        if (!$orderby) {
            return $terms;
        }

        // Custom sorting that WordPress can't do
        $field = $instance->getField($orderby);

        // Make sure we're sorting numerically if appropriate
        // because WordPress is storing strings for all vals
        if ($field['type'] === 'number') {
            foreach ($terms as &$term) {
                if (!isset($term->$orderby)) {
                    continue;
                }
                if ($term->$orderby === '') {
                    continue;
                }

                $term->$orderby = (float) $term->$orderby;
            }
        }

        // Sorting
        $sort_flag = ($field['type'] === 'number') ? SORT_NUMERIC : SORT_STRING;
        $terms = Collection::sortBy($terms, $orderby, $sort_flag);
        if (strtoupper($order) === 'DESC') {
            $terms = array_reverse($terms, true);
        }

        // Convert back to string as WordPress stores it
        if ($field['type'] === 'number') {
            foreach ($terms as &$term) {
                if (!isset($term->$orderby)) {
                    continue;
                }
                if ($term->$orderby === '') {
                    continue;
                }

                $term->$orderby = (string) $term->$orderby;
            }
        }

        return $terms;
    }
public static function getWhere ( $ args = array ( ) ) { $ instance = Term \ Factory :: create ( get_called_class ( ) ) ; // Allow sorting both by core fields and custom fields // See: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters $ default_args = array ( 'orderby' => $ instance -> getDefaultOrderBy ( ) , 'order' => $ instance -> getDefaultOrder ( ) , 'hide_empty' => false , // Note: This goes against a WordPress get_terms default. But this seems more practical. ) ; $ criteria = array_merge ( $ default_args , $ args ) ; // Custom ordering $ orderby = null ; $ order = null ; $ wordpress_sortable_fields = array ( 'id' , 'name' , 'count' , 'slug' , 'term_group' , 'none' ) ; if ( array_key_exists ( 'orderby' , $ criteria ) && ! in_array ( $ criteria [ 'orderby' ] , $ wordpress_sortable_fields ) ) { $ orderby = $ criteria [ 'orderby' ] ; $ order = ( array_key_exists ( 'order' , $ criteria ) ) ? strtoupper ( $ criteria [ 'order' ] ) : 'ASC' ; unset ( $ criteria [ 'orderby' ] ) ; unset ( $ criteria [ 'order' ] ) ; } $ criteria [ 'taxonomy' ] = $ instance -> getTaxonomyKey ( ) ; $ terms = Term \ Factory :: createMultiple ( get_terms ( $ criteria ) ) ; // We might be done if ( ! Arr :: iterable ( $ terms ) ) { return $ terms ; } if ( ! $ orderby ) { return $ terms ; } // Custom sorting that WordPress can't do $ field = $ instance -> getField ( $ orderby ) ; // Make sure we're sorting numerically if appropriate // because WordPress is storing strings for all vals if ( $ field [ 'type' ] === 'number' ) { foreach ( $ terms as & $ term ) { if ( ! isset ( $ term -> $ orderby ) ) { continue ; } if ( $ term -> $ orderby === '' ) { continue ; } $ term -> $ orderby = ( float ) $ term -> $ orderby ; } } // Sorting $ sort_flag = ( $ field [ 'type' ] === 'number' ) ? SORT_NUMERIC : SORT_STRING ; $ terms = Collection :: sortBy ( $ terms , $ orderby , $ sort_flag ) ; if ( strtoupper ( $ order ) === 'DESC' ) { $ terms = array_reverse ( $ terms , true ) ; } // Convert back to string as WordPress stores it if ( $ field [ 'type' ] === 'number' ) { foreach ( $ terms as & $ term ) { if ( ! isset ( $ term -> $ orderby ) ) { continue ; } if ( $ term -> $ orderby === '' ) { continue ; } $ term -> $ orderby = ( string ) $ term -> $ orderby ; } } return $ terms ; }
Get terms with conditions
@param array $args
@return array
Get terms with conditions