You have to add meta_key
, orderby
and order
parameters to your query as described in the Codex: Order & Orderby Parameters:
<?php
$args = array(
'post_type' => 'teacher',
'paged' => $paged,
'meta_key' => 'last_login',
'orderby' => 'meta_value',
'order' => 'DESC'
);
$my_custom_query = new WP_Query($args);
Also note I don’t use $wp_query
variable to store the query. See WP_Query Usage for example and description why.
Related Posts:
- visually sort ordering “custom post types” for end users
- Custom Table Column Sortable by Taxonomy Query
- How to order users alphabetically by their last name?
- How do I allow users to sort posts? [duplicate]
- Sorting results from JSON-API on custom fields
- Sort users in get_users() in custom order
- Sort by custom field value
- How to sort posts with the first 2 or 3 by latest, and the rest is random?
- Get “wp_get_nav_menu_items” to sort alphabetically [duplicate]
- Ascending sort order for monthly & category view, i.e. ?m=201204, ?cat=4
- Adding Sorting to Website?
- How can I sort get_users() by any value (last_name, user defined fields and more)
- Sorting by tag or category
- get_terms orderby name as numbers
- Creating a category page by alphabet
- Sorting get_post_ancestors array
- wordpress custom_meta ordering of timestamps
- Multi-level ordering in WordPress
- Sorting for custom column in WordPress admin post table
- Help alphabetically sorting $terms from get terms(‘wpsc_product_category’
- Vertical alphabetically post columns
- Advanced custom fields sort repeater by date
- Displaying posts sorting by a custom criterion
- Sort posts by meta key that is serialised with other meta keys
- orderby field – list of available options?
- User Query sort on custom field then name
- WP Query sort by meta value
- Column Sorting Code on users.php
- Best Practices for a Completely Customizable Homepage – without plugins
- Sorting posts by custom field value
- How do I create a sort capability by Title, Category, Author, Date?
- How to avoid duplicating same meta_value?
- Sorting/Filter posts from front-end in WordPress blog
- ‘sort_column’ => ‘menu_order’ not working
- Sort scheduled posts in ascending order by default
- How to sort by number
- sort items by randomness
- inner foreach loop sorting
- Sortby parameter to sort users
- Update meta_key value for a page
- Sort my event calendar by date
- Sort users by meta key value even if meta key not present for all users
- Table Sorter sort by span title?
- make two custom columns sortables
- How to display remaining post ( in post__in ) if posts are less then post per page?
- Admin user column sort by numeric meta key
- ACF pro: Group teaser by datepicker year and display custom sub fields [closed]
- Sorting in WP_List_Table class
- meta_query orderby sort multiple keys
- Sort an array with an ACF meta key
- display wordpress user who published a pending post of another user
- Static front page and orderby
- Advanced sorting of content in wordpress [closed]
- Sort posts by first content letter
- Grouping posts starting with same letter
- Getshopped (WP-e-commerce): show all protucts on one admin page for drag-and-drop ordering [closed]
- List CPT by menu_order with children right after parent
- Multidimensional array sort?
- How can users sort multiple pages?
- Can’t sort custom column on user.php by number / meta_value_num?
- How do i Sort my Posts
- How to resort my id in wordpress?
- Sorting search results by taxonomy terms
- Custom Post Type, WP_Query and ‘orderby’
- Order posts by meta_value even if meta_key is not filled
- wp_get_current_user in custom file returns 0
- Calling a method from functions.php on a click of a button
- What’s the most efficient database method to add and query usermeta?
- Alphabetical sorting of custom post type – one letter per page
- SQL to check how many sites a user is a member of
- Issue with foreach on duplicate meta_key’s
- User meta conventions / name registry, for social media links
- Select User by Joining Multiple Meta Value Results
- Best way to tell if a user account is active, using the database only
- How to redirect on login to a specific page if a specific meta user is empty
- User last login and user last visit problem
- Sort entries by date mixing two post types
- Trying to sort and display categories(not posts) by custom field: ‘order’
- Display and Update User Custom Meta via user-edit.php
- WordPress REST API and User meta data
- Displaying field value in new column in users view on wordpress
- Solving a get_user_meta() problem in Multisite
- Updating user meta on save post
- How to output taxonomy term (incl. link to archive) on author.php?
- Plugin that lets visitors Like a post (not facebook) and stores likes in custom meta?
- How can I sort my loop based on meta data, using a form?
- sort title descending with title with number
- How to sort by multiple values in a nested WP_Query
- Sort posts on custom field AND after that sort on date?
- get_the_author_meta i want to write in a loop
- How to sort (orderby) a query done by a template function before the ‘foreach’ loop?
- WP Tax query & order by tax query not working
- How do I sort post listing by child post count?
- How to sort post_meta in edit.php?
- How does adding custom meta to signup form work?
- Dynamically Generating User Meta Field
- Strip Twitter Username from Profile Field with URL and Save to New Profile Field
- custom sort posts in archive/taxanomy page
- Update another users meta
- Filter/Sort Post Form On Taxonomy page