Title: Cannot sort checkboxes
Last modified: April 18, 2023

---

# Cannot sort checkboxes

 *  Resolved [MilenMK](https://wordpress.org/support/users/milenmk/)
 * (@milenmk)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/cannot-sort-checkboxes/)
 * Hell
 * We are using this plugin to output some filters of ACF fields. The fields (most)
   are checkboxes, and we cannot sort them properly, as they are mixed numbers and
   letters (length in our case).
   For example, we want:
 *     ```wp-block-code
       100 mm
       110 mm
       200 mm
       1200 mm
       ```
   
 * while we get
 *     ```wp-block-code
       100 mm
       110 mm
       1200 mm
       200 mm
       ```
   
 * We’ve tried both “default” and sort by “term name” with no luck. Is there a way
   to fix this?
    -  This topic was modified 2 years, 11 months ago by [MilenMK](https://wordpress.org/support/users/milenmk/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [stepasyuk](https://wordpress.org/support/users/stepasyuk/)
 * (@stepasyuk)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/cannot-sort-checkboxes/#post-16672553)
 * Hello [@milenmk](https://wordpress.org/support/users/milenmk/)
 * Thank you for choosing Filter Everything.
 * If no one from the sorting options was good for you you can use hook ‘`wpc_terms_before_display`’
   to sort them via code. Here is example of how to use the hook – [https://filtereverything.pro/resources/hooks/#terms-before-display-hook](https://filtereverything.pro/resources/hooks/#terms-before-display-hook)
 * Of course this expects that you are familiar with PHP or you have to ask a developer
   to help you with this.
 *  Thread Starter [MilenMK](https://wordpress.org/support/users/milenmk/)
 * (@milenmk)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/cannot-sort-checkboxes/#post-16684439)
 * Hello.
 * I’ve tried the proposed solutions, but it has no effect.
   We have an ACF field,
   and one that we have a problem with is named Length and has a slug `length`. 
   The output array for this field is like this:
 *     ```wp-block-code
       array(16){[3]=> object(stdClass)#41944 (6) {["term_id"]=> int(3)["slug"]=> string(7) "1000-mm"["name"]=> string(7) "1000 mm"["count"]=> int(192) ["cross_count"]=>int(47)["wp_queried"]=> bool(false)}[455]=> object(stdClass)#41945 (6) {["term_id"]=> int(455)["slug"]=> string(7) "1100-mm"["name"]=> string(7) "1100 mm"["count"]=> int(52)["cross_count"]=> int(13)["wp_queried"]=> bool(false)}[8]=> object(stdClass)#41982 (6) {["term_id"]=> int(8)["slug"]=> string(7) "2000-mm"["name"]=> string(7) "2000 mm"["count"]=> int(180)["cross_count"]=> int(43)["wp_queried"]=> bool(false)}[264]=> object(stdClass)#41874 (6) {["term_id"]=> int(264)["slug"]=> string(7) "3000-mm"["name"]=> string(7) "3000 mm"["count"]=> int(112)["cross_count"]=> int(23)["wp_queried"]=> bool(false)}[9]=> object(stdClass)#41873 (6) {["term_id"]=> int(9)["slug"]=> string(6) "400-mm"["name"]=> string(6) "400 mm"["count"]=> int(152)["cross_count"]=> int(37)["wp_queried"]=> bool(false)}}
       ```
   
 * And we’ve tried the proposed solution like this:
 *     ```wp-block-code
       function wpc_sort_terms_as_needed( $terms, $filter ) {
   
       	// pa_color - is desired taxonomy
       	if ( $filter['e_name'] == 'length' ) {
       		$newTerms = [];
       		foreach ( $terms as $k => $term ) {
       			$termOrder        = get_term_meta( $term->term_id, 'slug', true );
       			$term->menu_order = ( $termOrder !== false ) ? $termOrder : 0;
       			$newTerms[ $k ]   = $term;
       		}
   
       		// To sort in descending order
       		// usort( $newTerms, \FilterEverything\Filter\EntityManager::compareDesc('menu_order') );
       		// To sort in ascending order
       		usort( $newTerms, EntityManager::compareAsc( 'menu_order' ) );
   
       		return $newTerms;
       	}
   
       	return $terms;
       }
       ```
   
 * However, no matter what we try for `$termOrder` key (slug or name) the result
   visible on the frontend is:
 *     ```wp-block-code
       1000 mm
       1200 mm
       1400 mm
       1600 mm
       1800 mm
       2000 mm
       400 mm
       500 mm
       600 mm
       700 mm
       800 mm
       900 mm
       2300 mm
       2600 mm
       3000 mm
       1100 mm
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Cannot sort checkboxes’ is closed to new replies.

 * ![](https://ps.w.org/filter-everything/assets/icon-256x256.png?rev=3487105)
 * [Filter Everything — WordPress & WooCommerce Filters](https://wordpress.org/plugins/filter-everything/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/filter-everything/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/filter-everything/)
 * [Active Topics](https://wordpress.org/support/plugin/filter-everything/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/filter-everything/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/filter-everything/reviews/)

## Tags

 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [sorting](https://wordpress.org/support/topic-tag/sorting/)

 * 2 replies
 * 2 participants
 * Last reply from: [MilenMK](https://wordpress.org/support/users/milenmk/)
 * Last activity: [2 years, 11 months ago](https://wordpress.org/support/topic/cannot-sort-checkboxes/#post-16684439)
 * Status: resolved