The argument is orderby
not order_by
but I am not sure what sort_by
is. If that is a custom meta field you need to alter the query.
‘meta_value’ – Note that a ‘meta_key=keyname’ must also be present in
the query. Note also that the sorting will be alphabetical which is
fine for strings (i.e. words), but can be unexpected for numbers (e.g.
1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might
naturally expect). Use ‘meta_value_num’ instead for numeric values.
You need to pass one argument for the meta_key and another for the orderby
.
$args = array(
'post_type' => 'teacher',
'posts_per_page' => 30,
'meta_key' => 'sort_by',
'orderby' => 'meta_value',
'order'=>'ASC'
);
Related Posts:
- Best way to use Category & Custom Fields?
- Pre_get_posts comparison with custom field doesn’t work
- Delete custom post type metadata without deleting the post in admin area
- Retrieving custom post type fields without a post
- Best way to insert a js script in the header with custom fields and CPT
- Creating connections programmatically with common fields on CPT’s
- Amend posts using wp_insert_post
- Custom Fields as Post Type Options
- How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
- How to delete comma from the end of results? [closed]
- How to use TOC with ACF?
- Publish post and create additional posts with same content
- How to enable the user to add value through the admin panel?
- Get month and day from a Date Picker custom field
- Two plugins sharing the same custom post type registration
- custom fields not showing before get_header
- Creating multiple CPT posts from one Gravity form
- How to add post reference field to a plugin?
- Generate slug and meta data if meta field is empty
- pre_get_posts with multiple post types AND a meta_key
- Search form to find custom meta box generated data
- Calling specific page with wp query
- Custom Info Box at end of posts?
- How to get past and upcoming post by defining date in custom field?
- How to stop wp_query searching pages as well as the specified CPT
- Converting a checkbox filter for custom fields to a dropdown
- Post content is cleared when updating
- How do I add custom fields to posts without having to manually add everytime I post?
- Function not pulling image or text from custom post type
- Display Custom Post if custom field is marked
- Default custom column to off
- predefined custom field on registration page
- How to display custom post type ordered by a custom field date
- Selecting posts older than the current Unix epoch timestamp
- Unable to get the upcoming events for custom post
- Order Custom Posts by Several Fields
- one get_posts to return a number of custom posts for each meta value
- Show Custom Post Type taxonomy term that matches custom field
- display some fields in custom post backend
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- Query Distinct Taxonomies of Custom Post Type
- Custom Post Type as invoice or order template
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- Custom field totals
- custom taxonomies are not showing up in get_taxonomies
- WP_Query and two custom fields returns no posts
- Forms with multiple element types using custom post types
- Displaying database table in backend of wordpress
- WP_Query get posts where post_name is empty
- Is it good practice to search for custom posts based on custom field values?
- Custom post type with custom fields enabled, is there a way to set a default group of fileds?
- Storing/querying custom date data
- Custom post type won’t take my custom fields
- Order by custom field attribute
- Get result from Custom Field in Custom Post type
- If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
- Make each Value of custom field show related posts when clicked
- How to display Multi Checkbos select Custom Field on the post?
- I want to split this into two functions
- custom field suit new post with in custom fields
- Repeatable Custom Field for Media Upload
- Show a custom field instead of username in the backend author area
- Filter CPT based on meta box value using Flexible Posts widget?
- Echo custom field value
- Select Menu for Custom post Type does not save
- Customizing the display of custom post types
- Repeatable custom meta select boxes
- Create shortcode for list of custom post titles with custom fields alongside
- Display custom posts in checkbox list
- Display posts order by custom post in a dropdown menu
- Advanced search form with filters for custom taxonomies and custom fields
- Query recent posts by author
- 404 on Pages for Custom Post Type & Query_Posts
- Custom post type and custom taxonomy archive inaccessible
- How to insert post into a page?
- Textarea type on one field custom add_meta_box?
- How to show animal lineage/pedigree in WordPress?
- How can i display on front page a movie that is atached in a post type
- WP_Query arguments: Loop through custom post type – get all entries except excluded meta_key?
- Rewriting a page driven by custom fields to populate a page dynamically, like posts
- loop through custom post-type with two meta_keys
- How to store datetime from custom meta box so that it can be sorted by
- Extending a CPT by Created by another plugin
- Custom meta box includes
- Querying meta values within an array
- Creating entries with image attachements within posts and managing them in a list
- Types plugin isn’t compatible with my custom post type
- How to Create a Frontend Html-list Editable in the Backend?
- Allow authors to create article image
- Radom post image/link based on custom taxonomy
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Custom Post Meta on a Different Page?
- Calling Custom Post Meta
- Adding a custom “Add Custom Field” button to Custom Meta boxes
- preselected custom fields in custom post type
- how to implement club post type
- Filter Custom post type by another Custom post type
- Show Posts in Vertical Tabs with Scrollbar
- How do I filter a custom post type loop by a field?