Use usort
with a custom callback, like this:
function compare_term_order_numbers( \WP_Term $a, \WP_Term $b ) : int {
$order_number_a = get_field( 'order_number', $a );
$order_number_b = get_field( 'order_number', $b );
return strcmp( $order_number_a, $order_number_b );
}
usort($terms, 'compare_terms' );
Note that this assumes get_field
returns a plain string, not an object, that each term has the order_number
set and it isn’t empty, and that $terms
is an array of terms, not an error object or false
/null
.
More information at: https://www.php.net/manual/en/function.usort.php
Related Posts:
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- Get Custom Field Values by Another Custom Field in WordPress
- Retrieve value of a category’s custom field
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- ACF – Retrieve custom taxonomy from a relationship field
- Display Custom Field or Custom Taxonomy in front page /post/product
- Advanced search form with filters for custom taxonomies and custom fields
- How to Add Custom Fields to a Custom Post Type?
- Getting custom taxonomy from custom post type
- What should I use – Taxonomies, custom fields, Post Type?
- clients list using wordpress
- Custom Taxonomy Template Post List with Sort Order
- Automatically fill custom field value on post publish/update
- Creating Photo Gallery System with Custom Post Type
- How to do a custom bookmarks post type?
- How to sort a table of custom posts by column containing custom field
- Use Custom Post Type as Custom Field
- Custom Taxonomy order by Custom Field
- get terms that have post with custom post type between 2 values
- Custom post type / custom fields
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Linking three taxonomies with ACF
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- Query Custom Post Types by date (custom field) range
- Custom Posts Hierarchy? (State/City/Restaurant)
- Automatically populate a hierarchical taxonomy from a custom field
- wp_query to find posts by year and month
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Custom Post type and Custom Field WP_Query
- get_posts of Custom Post Type AND Custom Taxonomy
- How can I dynamically add a post to a custom post type which uses a custom field?
- How do I associate a custom post type with another through a taxonomy or storing an ID in a custom field?
- Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
- Show custom post type relationships by taxonomy
- Query custom post type with ACF Date
- Meta Query Not Returning Output Despite Having Matching Values
- ACF From & To Date Validations
- Order Custom Post Type by Custom Field Value
- Hierarchy and access control for Custom Post Types (CPT)
- First custom field value (out of several) displayed twice after query
- Lists custom taxonomy terms that has specific custom field value assigned to the term (not post)
- Multiple Frontend Filters Using Advanced Custom Fields
- How to display products name in a non-alphabetical order, in a custom field (taxonomy)?
- Displaying custom field according to date
- Show fields based on taxonomy selection in editor
- Permalinks: custom structure for taxonomy – tags?
- WebP Fallback for Inline Background Image in Style Attribute
- Creating custom post type with custom taxonomy and custom fields programatically
- How to inherit field value from parent post into in child / sub post
- Custom Taxonomy Search result page
- Custome fields not displayed
- How to get_term_meta on single custom post?
- Category Search / Custom Post Type search on my website. Custom Post Types that are “page-like”?
- Display a post from custom post type only if all the selected taxonomies and custom field value matches the record
- posttype and custom fields on multisite
- How do I get_the_postID() for a custom post that uses ACF repeater field?
- How to fetch custom post types with its full data on wordpress?
- How to populate a Gravity Forms Custom Post Field (dropdown type) with custom taxonomy terms? [closed]
- Get custom term meta problem on single post type
- Custom post type name and assigning custom taxonomy
- Group by custom field value (start and end times)
- Custom post types, disable fields
- Building a Portfolio and need some direction
- Excerpt length: get first paragraph
- Order custom posts by taxonomy, then by meta_key
- Confusion about how to use Custom Post Types, Custom Taxonomy or Category?
- Displaying Posts Using a Custom Query with a Custom Field and a term_id
- Writing a custom Glossary plugin
- add_filter get array data before display in custom post_type
- Having a repeating custom field in admin custom post type, what I’d go better with, for DB’s sake? ACF repeater or query a different post type?
- Custom front-end form for adding post – Category problem
- Create loop from selected terms in ACF taxonomy field
- Sort custom posts by date and then by taxonomy
- Display Posts that fit a certain criteria on Category pages
- WP_Query not using custom taxonomy categories on custom post type
- Filter posts by their related field’s custom field
- wp_insert_post deleting previous post custom meta
- If ACF Post Object post has custom taxonomy term…
- I want to create a metabox under custom taxonomy
- Taxonomy shows up twice on Custom Post Type
- Query posts by multiple custom fields
- Custom taxonomy template for custom fields loop [closed]
- Best way to have one product in both rental and sale parent category
- Create Inclusions and exclusions
- How do I display specific custom posts, and how do I edit a post’s singular page?
- What’s the most efficient way to get two queries based on an if statement?
- Automatically convert standard posts with custom fields to custom post types
- Can’t pick up a field created with Advanced Custom Fields
- Best way to use Category & Custom Fields?
- Get month and day from a Date Picker custom field
- How to query posts by meta keys AND under specific category?
- predefined custom field on registration page
- Show Custom Post Type taxonomy term that matches custom field
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- Storing/querying custom date data
- Order by custom field attribute
- Advanced Custom Fields: query posts filtered by multiple field values
- Custom post type and custom taxonomy archive inaccessible
- How to change order of custom post types. I want Featured post to come first
- Custom taxonomy meta fields