Found the answer from the WordPress docs.
For what the query is ordered by, I use:
global $wp_query;
echo $wp_query->get('orderby');
For the order by which the posts are queried:
global $wp_query;
echo $wp_query->get('order');
Related Posts:
- Display three sequential posts on each page load, without repeating previous
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Sorting: custom query with orderby meta_value_num THEN by title
- Order posts by ID in the given order
- How to order posts tag by tag?
- Loop through all tags & output posts in alphabetical list
- Woocommerce custom loop to show all the products [closed]
- Sort by meta key on archive page
- Show all parents and children in custom post type in right order
- Meta query with order by another custom field
- WP_Query Order by Specific Post ID First
- How do I sort posts with multiple pages
- Sort wordpress custom posts based on meta value
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- Understanding the orderby in WP_Query?
- Order by empty custom field
- How to order posts by title after they have already been sorted by category
- Help ordering Post loop by two meta values
- WP Query – order posts by meta field first and then order the rest
- How do I sort this custom list of sticky posts
- Filtering by multiple conditions in the loop
- WP_Query orderby random do not repeat infinite scroll – one loop
- orderby ignored by wp_query
- How to sort store location by specific category order in WP store locations
- How to sort wordpress posts already selected by WP_QUERY
- Order by value of Custom Field using url string
- WP Query with meta queries
- Order 2 meta_queries differently in WP_Query?
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- Sorting is not working in WordPress WP_Query
- Sorting: custom query with orderby meta_value_num THEN by title
- query_posts with sorting on a custom datestamp
- Order by multiple meta keys on wordpress
- Can I force WP_Query to return no results?
- Resetting post data to previous loop in nested loops
- Some doubts about how the main query and the custom query works in this custom theme?
- Get post count of current loop when using multiple queries on one page
- Multiple WP_Query loops with Pagination
- Using a custom WP_Query with get_template_part loop
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- WP_Query orderby date not working
- WP_Query vs get_posts
- Order by optional meta key?
- Loop within a loop?
- Order by DESC, ASC in custom WP_Query
- WP_Query and next_posts_link
- WP_Query order by multiple meta keys & fields
- Show posts without term
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Display products from specific category in shop page
- How to list some posts first in the loop based on post id
- Pagination returns 404 after page 20
- Make loop display posts by alphabetical order
- WP_Query: query posts by ids from array?
- Use WP_Query with have_posts()?
- Secondary Sort (fallback) for WP_Query
- Query Posts in a Predefined Order
- Sort posts by category name and title
- get custom post type by tag
- Custom WP_Query order by post_meta and (author) user_meta
- Sorting posts by custom date fields (non standard date format)
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- get_template_part in for loop
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- WP Query orderby meta key natural sort?
- Get array of posts from the current archive page loop
- pre_get_posts with get_posts
- How-to exclude terms from the main query the most performant way?
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Get the number of posts from the current page results
- How do I reorder (pop and push) items from WP_Query?
- Executing Queries in tag.php
- Display posts the match taxonomy term linked from wp_list_categoies?
- How can I save an array from a random post sequence for later use?
- How to place a loop within another loop?
- WordPress Custom Query to show posts from last x years
- Query Custom Meta Value with Increment
- How do I order pages and categories by ID or name in the same query?
- “pre_get_posts” firing on every query
- Show two random posts from custom post type
- Add the “active” class only to the first loop item in a WordPress query [closed]
- Pagination with 5 posts per page
- Reverse chronology of post listing
- How can I custom order the results from wp_list_categories?
- Identify which loop you are hooking into; primary or secondary?
- WP_Query ordered by custom field that is a date string?
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- In loop: posts have thumbnail AND other variables
- Group posts by custom field
- WP_Query sort by comment meta data
- How to order category.php loop by ‘meta_value’?
- Pagination/infinite scroll with WP_Query and multiple loops
- Order posts by tags count?
- Merging a complex query with post_rewind and splitting posts into two columns
- Sort posts by custom taxonomy name
- Merge 2 args in one WP_Query and order it by date
- Orderby = none not working [duplicate]
- Add inline HTML to posts published within last 24hrs
- Move posts to top of WP_Query if in certain Taxonomy?
- WP_query ‘orderby=none’ Problem