I am trying to order by post meta name which I added for post. Post meta is “_merchant_id” an I know how to sort by merchan_id but I don’t know how to sort by merchant name.
I am sorting by merchant id like this:
public function column_orderby( $vars ) {
if ( isset( $vars['orderby'] ) && is_admin() ) {
switch ( $vars['orderby'] ) {
case 'merchant':
$vars = array_merge( $vars, array(
'meta_key' => '_merchant_id',
'orderby' => 'meta_value_num'
) );
break;
...
Merchant is another post type (“merchant”). How can I sort by merchant name?
UPDATE (improved explanation by screenshot):
I assume merchant name is another meta field and not the title for that post type? If so, here is a way to organize your admin edit.php area
The meta values and names are not useable in admin area on default.
But you can enahnce the query to use it in the loop, the query like the example in your question. To add the meta values use the follow small snippet in plugin.
A other alternative is to hook in the query and change the query directly.
I hope that my solution will be useful to somebody.