Support » Plugins » alphabetical titles by custom field.

  • Hiya,

    So I have this lovely loop code by Michael, that makes some alphabetic headers in between my posts for an attendee list. Its awesome. The issue i am having now, tho, is that someone wants it to sort by attendee last name…

    I went ahead and made a custom field called ‘guest_sort’ and slotted everyone’s last names into them, then modified the loop. But now its getting jumbled. ie:

    beatrice Abrams, Morrisay Adurm

    clarice burnham
    Morris Finkler
    Justin Alaier


    I am not sure why, and I’m looking for some suggestions. The code looks like this:

    $last_char = '';
    $cat = 5;
      'cat' => $cat,
      'orderby' => 'guest_sort',
      'order' => 'ASC',
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post();
      $headers = get_post_meta($post->ID,'guest_sort',true);
        $this_char = strtoupper(substr($headers,0,1));
          if ($this_char != $last_char) {
          $last_char = $this_char;
          echo '<h2 class="full">'.$last_char.'</h2>';
          echo $last_char;
        } ?>

    If I take out the code that makes the headers, it seems to be sorting ok with ‘orderby’ because if there are no headers it just lists them by the custom field. So this only happens with the header code. I’m stumped.

    Thank you!

  • The topic ‘alphabetical titles by custom field.’ is closed to new replies.