wp_list_sort example


    public static function sort_wp_get_nav_menu_items( $items$menu$args ) {
        // @todo We should probably re-apply some constraints imposed by $args.         unset( $args['include'] );

        // Remove invalid items only in front end.         if ( ! is_admin() ) {
            $items = array_filter( $items, '_is_valid_nav_menu_item' );
        }

        if ( ARRAY_A === $args['output'] ) {
            $items = wp_list_sort(
                $items,
                array(
                    $args['output_key'] => 'ASC',
                )
            );
            $i     = 1;

            foreach ( $items as $k => $item ) {
                $items[ $k ]->{$args['output_key']} = $i++;
            }
        }

        
 else {
        $items = array();
    }

    $items = array_map( 'wp_setup_nav_menu_item', $items );

    if ( ! is_admin() ) { // Remove invalid items only on front end.         $items = array_filter( $items, '_is_valid_nav_menu_item' );
    }

    if ( ARRAY_A === $args['output'] ) {
        $items = wp_list_sort(
            $items,
            array(
                $args['output_key'] => 'ASC',
            )
        );

        $i = 1;

        foreach ( $items as $k => $item ) {
            $items[ $k ]->{$args['output_key']} = $i++;
        }
    }
'taxonomy'         => self::TAXONOMY,
                    'filter'           => 'raw',
                ),
                $setting_value
            );

            array_splice( $menus$index( -1 === $index ? 0 : 1 ), array( $menu_obj ) );
        }

        // Make sure the menu objects get re-sorted after an update/insert.         if ( ! $is_delete && ! empty( $args['orderby'] ) ) {
            $menus = wp_list_sort(
                $menus,
                array(
                    $args['orderby'] => 'ASC',
                )
            );
        }
        // @todo Add support for $args['hide_empty'] === true.
        return $menus;
    }

    
$permalink = apply_filters( 'pre_post_link', $permalink$post$leavename );

    if (
        $permalink &&
        ! wp_force_plain_post_permalink( $post )
    ) {

        $category = '';
        if ( str_contains( $permalink, '%category%' ) ) {
            $cats = get_the_category( $post->ID );
            if ( $cats ) {
                $cats = wp_list_sort(
                    $cats,
                    array(
                        'term_id' => 'ASC',
                    )
                );

                /** * Filters the category that gets used in the %category% permalink token. * * @since 3.5.0 * * @param WP_Term $cat The category to use in the permalink. * @param array $cats Array of all categories (WP_Term objects) associated with the post. * @param WP_Post $post The post in question. */

    public function prepare_controls() {

        $controls       = array();
        $this->controls = wp_list_sort(
            $this->controls,
            array(
                'priority'        => 'ASC',
                'instance_number' => 'ASC',
            ),
            'ASC',
            true
        );

        foreach ( $this->controls as $id => $control ) {
            if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() ) {
                
Home | Imprint | This part of the site doesn't use cookies.