I have a list of posts, one column of which I am trying to set in alphabetical order. The problem is that these posts have one of two different value types shown in the same column.
The code I have tried below gets me halfway there, it does query the posts with one of those values at the top but still not in alphabetical order.
$posts_per_page = 10;
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'offerter',
'post_status' => 'publish',
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'meta_key' => 'business_id',
'meta_value' => $business_id,
'meta_query' => array(
'relation' => 'OR',
'customer_name' => array(
'key' => 'customer_name',
'compare' => 'LIKE',
),
'quick_customer_name' => array(
'key' => 'quick_customer_name',
'compare' => 'LIKE',
),
),
'orderby' => array(
'customer_name' => 'desc',
'quick_customer_name' => 'desc',
)
I have tried to compare EXISTS and LIKE, which sort of gets me the same result.
you can use at last of of your query eg:
$collection = new Collection($put_your_array_here);
// Paginate
$perPage = 10; // Item per page
$currentPage = Input::get('page') - 1; // url.com/test?page=2
$pagedData = $collection->slice($currentPage * $perPage, $perPage)->all();
$collection= Paginator::make($pagedData, count($collection), $perPage)->orderby('customer_name' => 'desc')->orderby('customer_name' => 'desc');