0

I am trying to sort my custom post type in a few different ways using a dropdown.

When I try to sort it as the display_name it doesn't work.

$wp_query = new WP_Query(array('orderby' => 'display_name') );

It works well on a few other sort ways like 'title' 'comment_count' but when I want to sort from the authors real name and not username it doesn't work anymore. Any hint how this can be fixed?

4
  • I fixed this issue by adding a new post_meta to my custom_post_type... which added both add_post_meta($post->ID, 'mlp_author', $current_user->first_name . $current_user->last_name); Then sorting by that post_meta using: array('meta_key' => 'mlp_author', 'orderby => 'meta_value')
    – murum
    Mar 18, 2013 at 19:38
  • You should add your solution as an answer and "accept" it.
    – s_ha_dum
    Mar 18, 2013 at 19:46
  • Have you seen this question: Sort custom post type list table by display name of a user id stored as post meta value
    – fuxia
    Mar 18, 2013 at 22:43
  • s_ha_dum - I will do that now, but I couldn't do it yesterday because I've to few points. toscho - I think I went through that yesterday when I were searching for an answer but I thought there could be an easier way to fix it. Atleast that wasn't exactly the same way I wanted to do this.
    – murum
    Mar 19, 2013 at 15:32

1 Answer 1

0

I fixed this issue by adding a new post_meta to my custom_post_type... which added both

add_post_meta($postid$current_user->first_name . $current_user->last_name;

Then sorting by that post_meta using:

array('meta_key' => 'mlp_author', 'orderby => 'meta_value')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.