5

How can I get the order through which the query is done?

For example, my woocommerce product archive page is querying by ordering according to the order_by select box (as seen below).

How can I get what my posts are ordered by?

For example, if it's default sorting, I want to know. If it's by popularity, I want to know. If it's by newness, I want to know.

enter image description here

  • 3
    The down/close votes are probably from members who are doing this by default the moment they see the word WooCommerce. :( However, your question applies to any post type, it is interesting and on-topic. Good to see that you solved it already. – fuxia Jan 11 '15 at 9:28
5

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');
  • 2
    @cybmeta Yeah, but I have to wait for two days. I will. – yaharga Jan 11 '15 at 10:02
  • 1
    2 days have passed. You can mark it now :) – Lea Cohen Feb 8 '15 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.