WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to reorder a custom field from one of my Custom Post Types.

I'd like to get the custom field string which is called 'first name' and order all of the first names by their string length. Does this makes sense ? Thanks. I have managed to do this which sort the custom fields by the ABC :

'post_type' => 'employees',
'posts_per_page' => 150,
'meta_key' => 'wpcf-first-name',
'orderby' => 'meta_value',
'order' => 'ASC');
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?>

<li><?php the_title(); ?> and what else do is in the loop...</li>
<?php endwhile; }
wp_reset_query();  // Restore global post data stomped by the_post().
share|improve this question
Post your code please. Are you trying to do this with a query or are you trying to order data after the query has run? – s_ha_dum Jun 6 '13 at 23:36
Each field has multiple values. Which one do you want to use for ordering? – toscho Jun 7 '13 at 6:32
I have got this - a list of employees (CPT) that have a custom fiels of first-name, and I'm trying to order them by the length of their first name string, up to now I have got to here, which sorts them by the ABC – Limor Jun 8 '13 at 7:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.