When you do WP_Query in WordPress, orderby
is your friend to get things in order. It’s the argument passed on to tell MySQL server which column to sort on when it’s creating the Order By
clause.
It’s pretty straightforward to get only one column sorted but things will get a bit complicate when there are multiple ones to take care of.
To sort by multiple columns with WP_Query, you can pass an array to the query as the value for orderby
. For example,
$q = new WP_Query( array( 'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ) );
But that’s not enough, you will need to make a Meta_Query to describe the columns that you need to put them in order. The whole thing would look like this:
$q = new WP_Query( array( 'meta_query' => array( 'relation' => 'AND', 'title_clause' => array( 'key' => 'title', 'compare' => 'EXISTS' ), 'menu_order_clause' => array( 'key' => 'menu_order', 'compare' => 'EXISTS' ), array( 'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ) ) );
If using Copilot right from the Taskbar isn't your thing, you should disable it. Even…
In an environment where standardizing things does matter, setting default fonts in Microsoft Office apps…
Wake-On-LAN is a networking standard that lets you wake up a computer from either a…
First of all, this is not to bypass a PDF file that requires a password…
Microsoft has been lurking about the idea of placing the Outlook navigation bar to the…
One colleague came up to me the other day asking me to take look at…