Orderby custom field (meta_key)
-
On the about page of my website (https://it4.wickedsmartdesign.net/about/), I have the employees listed alphabetically on the left-hand side. I’ve achieved this by using a user query (WP_User_Query). However, instead of having them listed alphabetically, I want them to be ordered by a custom field (‘about_order’). Below you can see my attempt, yet I can’t get it to work. Any ideas?
/* Employee Query for About page */ function it4_get_users_with_job_title() { $args = array( 'orderby' => 'meta_value', 'meta_query' => array( array( 'key' => 'about_order', ), array( 'key' => 'job_title', 'value' => null, 'compare' => '!=' // Make sure the user's job title field has a value (i.e. job_title != null) ) ), // End of meta_query 'fields' => 'ID', 'exclude' => array( 1 ), ); $user_query = new WP_User_Query( $args ); return $user_query->get_results(); }
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Orderby custom field (meta_key)’ is closed to new replies.