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?
- Sort Featured Content by Order instead of ID
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- How to create a front end user profile with a friendly permalink
- Sort results by name & asc order on Archive.php
- user_login vs. user_nicename
- How to get a buddypress user profile link and a certain user profile field for the current post author?
- how to get list of all users and their metadata
- How do I set the default admin sort order for a custom post type to a custom column?
- Adding fields to the “Add New User” screen in the dashboard
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Difference between update_user_meta and update_user_option
- add_user_meta() vs update_user_meta()
- Make custom column sortable
- How to filter users on admin users page by custom meta field?
- Sort pages in loop by admin’s page attributes order field?
- How to Change Order of Posts in Admin?
- get_user_meta() doesn’t include user email?
- Orderby meta_value only returns posts that have existing meta_key
- Using meta_query, how can i filter by a custom field and order by another one?
- How do you update user_email on the front end in WP 3.3?
- Sort admin menu items
- Add default WordPress tag meta box to User Profile
- ORDER BY custom field value
- How to make a custom column on the Users admin screen sortable?
- wp_update_user not updating
- Automatically delete inactive users after 2 months
- Sorting: custom query with orderby meta_value_num THEN by title
- How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?
- Check if user is admin by user ID
- group search results by post type?
- register_post_type sort order by title by default
- Random sort within an already sorted query
- Create custom user role (client) that can create another custom user role (employee) of that client
- Query users by custom taxonomy and user role
- wp_update_user doesn’t update and update_user_meta does
- Different post sort order within different categories
- Get basic Image Uploader on User Profile Page