Contents
How do I sort by multiple meta keys?
Each of my meta queries has a key associated with it. For the numerical metadata I’m specifying ‘type’ => ‘NUMERIC’ so that when I sort using it, it uses ‘meta_value_num’ instead of ‘meta_value’ ( more info ). In the theme file, the dropdown menu adds a GET variable for specifying the sort order.
How to sort posts by multiple meta keys in WordPress?
WordPress doesn’t let you sort posts by multiple custom field values or keys if you’re using a meta_query. With a filter in your (child) theme’s functions.php you can order the posts with a new query parameter meta_query_orderby. The new parameter can be used in WP_Query and pre_get_posts.
Can a query be ordered by multiple meta keys?
But you could still only have one based on metadata since it requires the ‘meta_key’ parameter. For example: Luckily WordPress 4.2 takes this even further, so now we can easily order by multiple meta keys. Here’s the details ( thanks Brian Krogsgard for reminding me of this ).
How to sort by Price in WordPress query?
The client wants Top Picks to always show up first. So if they select it to sort by Price (Low to High), it will first display all the Top Picks sorted by price low to high, then the other reviews sorted by price low to high. WordPress 4.0 allowed you to specify multiple orderby parameters and set the order of each independently ( details here ).
How do you sort a wiki in order?
A sortable table is identified by the arrows in each of its header cells. Clicking them will cause the table rows to sort based on the selected column, in ascending order first, and subsequently toggling between ascending and descending order. Links and other wiki-markup are not possible in headers.
How to query by Meta key in WordPress?
Step 2 You set meta_keyin your query to my_meta_key. This tells WordPress to query for posts that have that key. Step 3 Set orderbyin your query to meta_value_num. This tells WordPress to not only query posts with my_meta_key, but to also order numerically by that key. That query argument is the only place you will ever see or use meta_value_num.
How to generate order by Meta key in WordPress?
Step 1 Assign whatever value you want to your meta key, let’s call it my_meta_key, for each post to generate whatever order you want. Step 2 You set meta_keyin your query to my_meta_key. This tells WordPress to query for posts that have that key.
How to sort results by price, rating and post date?
Users can sort the results by Price, Rating and Post Date. The client wants Top Picks to always show up first. So if they select it to sort by Price (Low to High), it will first display all the Top Picks sorted by price low to high, then the other reviews sorted by price low to high.
How to query by meta value in WordPress?
This tells WordPress to query for posts that have that key. Step 3 Set orderbyin your query to meta_value_num. This tells WordPress to not only query posts with my_meta_key, but to also order numerically by that key. That query argument is the only place you will ever see or use meta_value_num. – MiloApr 25 ’17 at 18:21 2