admin管理员组

文章数量:1335443

I have two custom post types

  1. case
  2. 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

  1. case
  2. 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
Add a comment  | 

2 Answers 2

Reset to default 2

You 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