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
- Get post count of current loop when using multiple queries on one page
- WP_Query orderby date not working
- Order by DESC, ASC in custom WP_Query
- Display products from specific category in shop page
- Secondary Sort (fallback) for WP_Query
- Query Posts in a Predefined Order
- get_template_part in for loop
- “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]
- WP_Query ordered by custom field that is a date string?
- Loop inside the loop
- cloning a WP_Query
- How to query ‘posts_per_page’ to display a different blog posts index template?
- How is WP_Query connected to WP_Post in The Loop?
- Query Set Order By Author
- WordPress: Keep order of query_posts list of post ID’s using post__in
- How to use order RAND() on WordPress?
- How can I pick a single post from the latest 3?
- Get posts for last working week in WP_Query
- How to orderby meta_value_num with dollar ($) sign
- query user display_name failed in a custom mysql query foreach
- Order WP_Query by multiple fields, subtracting them from one another
- Query posts by specific word on title
- Multiple taxonomy And acf filter group by
- Reset postdata to custom query in nested queries
- How to Filter Posts by Custom Fields?
- WP_Query orderby author__in
- Loop Split two Columns
- How to list posts with disabled/closed comments, with pagination?
- How to make a second query offset -2 from current post
- Wp_query with 2 meta keys and array of meta values
- How to order WP_Query to group results?
- How to create custom query by keyword in post title?
- Create a loop on my pages with new “WP_Query”
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- WP ForLoop to compare meta information of posts to determine what post to display
- How to use a dropdown to filter posts by custom field
- Different Loop for tag pages?
- 2 queries with counters
- Orderby two meta fields not working
- Search.php – return number of results but cannot loop through
- Creating ‘posts page’ loop based on the page itself
- Custom wp_query inside a conditional stament inside a template part doesn’t work: why?
- Duplice post with standard WP loop – fixed by using query_posts() instead
- Custom order of posts in wp_query and different taxonomies
- WordPress Query custom ordering by temporary variable
- Check the stored / cached WP_Query with transients on post change
- New template file does not load category-specific post
- Get categories within specific term
- Custom query for custom post type not getting correct post ID
- Query post with content only
- How to get_comments() ordered by date and parent?
- Why is my query not giving results?
- Wrap group of wp query posts to parent div by date/year
- Continue loop after $queryObject
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- Show sticky post before other WP_Query
- List ALL posts within last week from current category on category page
- loop through custom post types with meta data
- Using Query In Post Type Archives
- Multiple loops on index page with sticky post and pagination
- the_excerpt() not working in custom archive
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- WP_Query sort by ACF date field (newest first) with blank dates first
- Pagination only showed when no category is set in wp_query
- Sort by multiple columns using get_posts