I have two custom post types
- case
- client
In case post type I have a ACF custom field to choose a client, so each case have a single client.
Now what is working: I am displaying all cases on a page and able to filter them using a client Id.
Whats I want: I want to get a list of cases (of all clients) and the order by sorting should be a client title ASC.
I am able to apply order by using client Id but I want order by client title.
Please suggest an solution for this.
$args = array(
'post_type' => 'case',
'post_status' => 'publish',
'orderby' => 'meta_value_num',
'meta_key' => 'client',
'posts_per_page' => 9
);
I have two custom post types
- case
- client
In case post type I have a ACF custom field to choose a client, so each case have a single client.
Now what is working: I am displaying all cases on a page and able to filter them using a client Id.
Whats I want: I want to get a list of cases (of all clients) and the order by sorting should be a client title ASC.
I am able to apply order by using client Id but I want order by client title.
Please suggest an solution for this.
$args = array(
'post_type' => 'case',
'post_status' => 'publish',
'orderby' => 'meta_value_num',
'meta_key' => 'client',
'posts_per_page' => 9
);
Share
Improve this question
asked Jun 5, 2020 at 4:21
Kishor PatidarKishor Patidar
1012 bronze badges
1
- Can you share your ACF custom field code here as well as post type creation code. – Baikare Sandeep Commented Jun 5, 2020 at 12:54
2 Answers
Reset to default 2You can use the order
and orderby
param in WP_Query
argument like below:
$args = array(
'post_type' => 'case',
'post_status' => 'publish',
'meta_key' => 'client',
'posts_per_page' => 9,
'orderby' => 'title',
'order' => 'ASC',
);
$query = new WP_Query( $args );
It will list out your posts by title. For more information check official WordPress document
You can try this:
$args = array(
'post_type' => 'case',
'post_status' => 'publish',
'orderby' => 'meta_value',
'order' => ASC,
'meta_key' => 'client',
'posts_per_page' => 9
);
More information of orderby parameters