admin管理员组文章数量:1335443
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
本文标签: plugin developmentHow I can use order by of the custom post title
版权声明:本文标题:plugin development - How I can use order by of the custom post title? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742373272a2462655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论